Lavanya, Thanks again for your report and fix.
While testing this I found that there was an additional error in the same piece of generated code when running under Python 3. (I'm guessing that you are using Python 2.) The generated code needs to convert the result of the etree.tostring call to a str object (instead of a bytes object). So, I added that fix, also. And, I made your test a little more specific. I tested for None instead of catching an exception. Maybe it's just me, but I have an aversion to catching all exceptions, because it might hide some other exception. So now, the generated code looks something like this: if nodeName_ == 'language_version': mo_ = PRESERVE_CDATA_TAGS_PAT.search(etree_.tostring(child_).strip().decode()) if mo_ is None: language_version_ = '' else: language_version_ = mo_.group(1) language_version_ = self.gds_validate_string(language_version_, node, 'language_version') self.language_version = language_version_ One question -- When the pattern match fails, and mo_ is None, should we use a value of an empty string or a single blank. I'm guessing that we want an empty string (so that, after parse and export, we get a result that matches the original XML). But, your message (below) shows a string with a single blank. Do you have an opinion on this? Here is the patch if you want it. I've also pushed this change to Bitbucket (https://bitbucket.org/dkuhlman/generateds): --- a/generateDS.py Wed May 09 11:13:02 2018 -0700 +++ b/generateDS.py Tue May 15 15:06:47 2018 -0700 @@ -3640,8 +3640,11 @@ wrt(" %s nodeName_ == '%s':\n" % (keyword, origName, )) if PreserveCdataTags: wrt(" mo_ = PRESERVE_CDATA_TAGS_PAT.search(" - "etree_.tostring(child_).strip())\n") - wrt(" %s_ = mo_.group(1)\n" % name) + "etree_.tostring(child_).strip().decode())\n") + wrt(" if mo_ is None:\n") + wrt(" %s_ = ''\n" % name) + wrt(" else:\n") + wrt(" %s_ = mo_.group(1)\n" % name) else: wrt(" %s_ = child_.text\n" % name) if childType == TokenType: I appreciate your help with this. Your sample schema and XML instance document that reproduced the problem was very helpful. Please let me know whether this solves the problem for you. Dave On Tue, May 15, 2018 at 12:11:36PM +0000, Poondru, Lavanya - FAS GmbH wrote: > Dear Mr. Kuhlman, > > Thank you very much for making a super successful project generateDS.py which > generates Python data structures from an XSD schema. > > I want to report a bug concerning the parser generated using generateDS: > > I have an XML document which contains header as below: > > <header> > <language_version>2.0</language_version> > <author>TTX-Mwcodegenerator</author> > <date_creation></date_creation> > <date_change/> > <description>SET</description> > </header> > > The corresponding schema is as below: > > <?xml version="1.0" encoding="UTF-8"?> > <xsd:schema elementFormDefault="qualified" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:adtf="adtf"> > <xsd:complexType name="Header"> > <xsd:sequence> > <xsd:element name="language_version" type="xsd:string" > minOccurs="1"></xsd:element> > <xsd:element name="author" type="xsd:string" > minOccurs="1"></xsd:element> > <xsd:element name="date_creation" type="xsd:string" > minOccurs="1"></xsd:element> > <xsd:element name="date_change" type="xsd:string" > minOccurs="1"></xsd:element> > <xsd:element name="description" type="xsd:string" > minOccurs="1"></xsd:element> > <xsd:element name="ext_declaration" type="ExtDeclaration" > minOccurs="0" maxOccurs="unbounded"></xsd:element> > </xsd:sequence> > </xsd:complexType> > > </xsd:schema> > > The parser generated using generateDS fails using the above schema. The > failure occurs in generateDS.py where in the definition of > generateBuildStandard_1: a condition says: > > if PreserveCdataTags: > > wrt(" mo_ = > PRESERVE_CDATA_TAGS_PAT.search(""etree_.tostring(child_).strip())\n") > wrt(" %s_ = mo_.group(1)\n" % name) > > > here the case is not considered if mo_ can be None . By adding a try except > block could solve the problem. > > if PreserveCdataTags: > > wrt(" mo_ = > PRESERVE_CDATA_TAGS_PAT.search(""etree_.tostring(child_).strip())\n") > > wrt("try :") > wrt(" %s_ = mo_.group(1)\n" % name) > > wrt("except:") > > wrt(" %s_ = ' '\n" % name) > > > > Thank you very much. A release might be really helpful. > > > > Best Regards > > Lavanya > > -- 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