Bernd, Thank you for your notes on this issue.
I'm still trying to think this one through. I'm still a bit confused about it. However, here is one item that may help. The `namespace_` parameter is mis-named I suppose; its value should be a namespace prefix and a colon. That value should be something like this: "abc:". If you were to pass something like "xyz:" as the value of the `namespace_` parameter, would that fix one of your issues? By the way: I believe that the documentation included near the top of a generated module, is not correct. It incorrectly reads: # A sample table is: # # # File: generatedsnamespaces.py # # GenerateDSNamespaceDefs = { # "ElementtypeA": "http://www.xxx.com/namespaceA", # "ElementtypeB": "http://www.xxx.com/namespaceB", # } whereas, it should be: # A sample table is: # # # File: generatedsnamespaces.py # # GenerateDSNamespaceDefs = { # "ElementtypeA": 'xmlns:nsa="http://www.xxx.com/namespaceA"', # "ElementtypeB": 'xmlns:nsb="http://www.xxx.com/namespaceB"', # } With respect to your issue 2: > 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. I believe that the namespace definition that you are passing in as the 2nd parameter is getting attached to the namespace_ parameter, whereas you actually want to set the namespacedef_ parameter. You might consider using a keyword argument to make this explicit. Example: testxml.export( output, 0, namespacedef_='xmlns="http://uri.etsi.org/02657/v1.18.1#/RetainedData"' ) While trying to straighten my head out on this, I wrote up the following notes on the parameters to the `export` methods. Arguments to the generated export method: - outfile -- A file like object open for writing. - level -- the indentation level. If the pretty_print argument is True, the (generated) function showIndent is used to prefix each exported line with 4 spaces for each level of indent. - namespace_ -- An empty string or an XML namespace prefix plus a colon, example "abc:". This value is printed immediately in front of the tag name. - name_ -- The element tag name. Note that the tag name can be overridden by the original_tagname_, which can be set by the class constructor. - namespacedef_ -- Zero or more namespace prefix definitions. Actually, its value can be any attribute-value pairs. Examples: '' 'xmlns:abc="http://www.abc.com"http://www.def.com" 'xmlns:abc="http://www.abc.com xmlns:def="http://www.def.com" or, because it is printed where the attributes occur, even: 'size="25" color="blue"' For more on namespacedef_, see: http://www.davekuhlman.org/generateDS.html#namespaces-inserting-namespace-definition-in-exported-documents - pretty_print -- If True, exported output is printed with indentation and newlines. If False, indentation and newlines are omitted, which produces a more compact representation. I've added the above notes to the generateDS document. See: http://www.davekuhlman.org/generateDS.html#method-export Sigh. XML namespaces make my head hurt. I'll study this and your notes a bit more. There must be *some* way we can make sense of this and get it to work correctly. Hope your weekend is (or was) a good one. Dave On Thu, Aug 09, 2018 at 10:14:57AM +0000, Zimmermann, Bernd wrote: > 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 -- 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