Hello Dave,

thank you very much for the patch for the validate patterns, it works 😉 so it 
could go productive on your next release.

Just a few additional remarks on the export issue:

Code: def export(self, outfile, level, namespace_='', 
name_='RetainedDataMessage', namespacedef_='', pretty_print=True):
There are three possible parameters: namespace_, name_, namespacedef_

The line: outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + 
namespacedef_ or '', ))
will print:
<namespace_ , name_, namespacedef_> if all three values are set.
Note: namespacedef_ may be set via GenerateDSNamespaceDefs option.

Here is just a first problem, because the namespace must be a second value in 
the xml tag
<OBJECT_NAME NAMESPACE>
</OBJECT_NAME>
in a valid xml, not the first.

TESTing:
1.)
using: testxml.export(output, 0, '', 'retainedDataMessage')
results in:
<retainedDataMessage xmlns="http://uri.etsi.org/02657/v1.18.1#/RetainedData";>
...
</retainedDataMessage>

this ist Ok.
Note that GenerateDSNamespaceDefs is set in my test case.
Parameter namespace_ is empty.
Parameter name_ is set
Parameter namespacedef_ is not used but overwritten by:
imported_ns_def_ = GenerateDSNamespaceDefs_.get('RetainedDataMessage')
        if imported_ns_def_ is not None:
            namespacedef_ = imported_ns_def_

2.)
OUTPUT with testxml.export(output, 0, 
'xmlns="http://uri.etsi.org/02657/v1.18.1#/RetainedData";')
results in:
<xmlns="http://uri.etsi.org/02657/v1.18.1#/RetainedData"RetainedDataMessage 
xmlns="http://uri.etsi.org/02657/v1.18.1#/RetainedData";>
</xmlns="http://uri.etsi.org/02657/v1.18.1#/RetainedData"RetainedDataMessage>

This is not correct.
There is the problem as stated above that the namespace_ is set und printed out 
at first in the opening tag before the name_

The logical problem is: The parameter namespace_ is set (the first one) and 
there is an GenerateDSNamespaceDefs setting, so
there is a logic missing, to decide which parameter to use in the export if 
there are 2 possibilities.
My suggestion would be to always use namespacedef_ it set and use the value via 
GenerateDSNamespaceDefs setting only
if namespacedef_ parameter is not used or set.

So for me it looks like to adjust the lines with outfile.write('< and 
outfile.write('> to match an valid XML form like:
<OBJECT_NAME NAMESPACE>
</OBJECT_NAME>

Hope you guess what I mean.

Best wishes,
Bernd

-----Ursprüngliche Nachricht-----
Von: Dave Kuhlman [mailto:dkuhl...@davekuhlman.org] 
Gesendet: Dienstag, 24. Juli 2018 23:03
An: Zimmermann, Bernd <bernd.zimmerm...@qsc.de>
Cc: generateds-users <generateds-users@lists.sourceforge.net>
Betreff: Re: [Generateds-users] validate_XXX_patterns generated wrong from XSD 
and Problems with export and namspaces

Bernd,

With respect to the validation of time and the 
validate_GeneralizedTime_patterns_, I've attached a patch.  With this patch, I 
believe that generateDS.py produces the pattern that works for you.  These 
regular expressions are complicated enough, and I'm in the dark about what they 
should and should not be checking.  So, if this patch works for you, let's go 
with it.  We can make adjustments when someone else reports a problem with it.

Here is a little explanation, as far as I can understand it: This patch removes 
the code that was replacing "|" with "$|^".  That replacement was intended to 
enable us to handle alternatives in regular expressions by breaking them up 
into several concatenated expressions.  *But*, maybe the ability to handle 
those alternatives is (or should be) written into the regular expression 
itself, *if* the author of the XML schema writes them correctly.  If so, the 
replacement that we are removing is not needed, and this patch is the right 
thing to do.  At least, that's what I'm hoping.

About your other issue, I'll take a look tomorrow.  But, at first glance, it 
looks like the values you are passing in to the export method are being 
attached to the wrong arguments.  You are passing positional arguments.  You 
could try using the keyword arguments:

    namespace_
    name_
    namespacedef_

You will have to look at one of the export methods to see how each of those 
parameters is used.

By the way, your suggestion in your latest email that a module generated by 
generateDS.py be able to do an automatic validation of the exported XML 
instance document seems like a good idea.  Although adding something like this 
line:

    xmllint --schema test.xsd test01.xml

to a batch file does seem like an easy enough way to handle that.
So, I'll put that feature on a "do" list, but it might not be at the very top 
of the list.

More later.  Thanks again for your help with these issues.

Dave

On Thu, Jul 19, 2018 at 12:19:52PM +0000, Zimmermann, Bernd wrote:
> Hello Dave,
> 
> very great stuff you've done with generateDS, works like a charm but only 
> after a resolving a few little things.
> 
> First on, this might be a bug:
> 
> XSD Pattern:
> 
> <xsd:simpleType name="GeneralizedTime">
>     <xsd:restriction base="xsd:string">
>         <xsd:pattern 
> value="\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9])([0-5][0-9])(.[0-9][0-9]*)?(Z|[\+|\-][0-9]{4})"/>
>     </xsd:restriction>
> </xsd:simpleType>
> 
> results in:
> 
> 
> validate_GeneralizedTime_patterns_ = 
> [['^\\d{4}(0[1-9]$|^1[012])(0[1-9]$|^[12][0-9]$|^3[01])([01][0-9]$|^2[
> 0-3])([0-5][0-9])([0-5][0-9])(.[0-9][0-9]*)?(Z$|^[\\+$|^\\-][0-9]{4})$
> ']]
> 
> which give the warning:
> 
> 
> /var/etsi/work/V1.18.1/Natparas2V18.py:7644: UserWarning: Value 
> "b'20180719123801+0200'" does not match xsd pattern
> restrictions: 
> [['^\\d{4}(0[1-9]$|^1[012])(0[1-9]$|^[12][0-9]$|^3[01])([01][0-9]$|^2[
> 0-3])([0-5][0-9])([0-5][0-9])(.[0-9][0-9]*)?(Z$|^[\\+$|^\\-][0-9]{4})$
> ']] warnings_.warn('Value "%s" does not match xsd pattern 
> restrictions: %s' % (value.encode('utf-8'), 
> self.validate_GeneralizedTime_patterns_, ))
> 
> Adjusting to:
> 
> 
> validate_GeneralizedTime_patterns_ = 
> [['^\\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0
> -5][0-9])([0-5][0-9])(.[0-9][0-9]*)?(Z|[\\+|\\-][0-9]{4})$']]
> 
> gives no warning.
> 
> So it might be a problem with the separator | which results in a wrong ^|$ 
> pattern?
> 
> 
> Second one, discovering a problem with:
> 
> testxml.export(sys.stdout, 0, '', 'retainedDataMessage')
> at:
> outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + 
> namespacedef_ or '', ))
> 
> This works correct, printing out <retainedDataMessage> or with a 
> generatednamespaces.py with GenerateDSNamespaceDefs the 
> <retainedDataMessage NSGIVEN>
> 
> But:
> 
> testxml.export(sys.stdout, 0, 'NSDATA', 'retainedDataMessage')
> 
> gives: <NSDATAretainedDataMessage> which is not correct, it should be 
> <retainedDataMessage NSDATA>, so it's printed in the wrong order and a space 
> is missing between the two arguments.
> 
> Perhaps a:
> outfile.write('<%s%s%s' % (name_, namespace_ and ' ' + namespace_ or 
> '', namespacedef_ and ' ' + namespacedef_ or '', ))
> 
> could fix this. Note: the closing tag must be adjusted too.
> 
> Perhaps the export could also be adjusted to overwrite the namespacedef_ if a 
> namespace_ is given or vice versa ...
> 
> I am using the latest version 2.29.17 installed via pip under Python 
> 3.7
> 
> Hope you could fix it.
> 
> Again, great work!
> 
> Best regards,
> Bernd
> 

> ----------------------------------------------------------------------
> -------- Check out the vibrant tech community on one of the world's 
> most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

> _______________________________________________
> generateds-users mailing list
> generateds-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/generateds-users



-- 

Dave Kuhlman
http://www.davekuhlman.org
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to