Dear Dave, Thank you for providing the patch so quickly! This has solved the issue. The check on whether the variable has a value looks safe enough for me to work in all the cases, but perhaps someone else can see what might go wrong.
Best regards, Andrii On 23/09/2016 00:42, Dave Kuhlman wrote: > On Thu, Sep 22, 2016 at 01:03:43PM +0100, Andrii Iudin wrote: >> Dear Dave, >> >> I am experiencing the following issue: >> I try to generate the structure with an element >> <xs:element name="country" type="xs:token" minOccurs="0"/> >> >> with a facet: >> whiteSpace="collapse" >> >> This results in the following Python code in "buildChildren": >> elif nodeName_ == 'country': >> country_ = child_.text >> country_ = re_.sub(String_cleanup_pat_, " ", country_).strip() >> country_ = self.gds_validate_string(country_, node, 'country') >> self.country = country_ >> >> When the element "country" is empty in the XML file that is being >> processed with parseString from the generated Python module, it fails on >> the regex substitution line. >> >> This works fine if I use "xs:string" with whiteSpace="preserve", in >> which case the regex line is not generated. >> >> Please could you tell if this is an intended behaviour in case if >> minOccurs="0" is specified? > That looks like a bug to me. Even if the XML file were not valid > (for example, if minOccurs="1" and the element were missing > completely), I'd prefer that the generated code > parse the XML instance document OK, and leave it up to the user to > use xmllint or some other validator to detect that error. > > It looks to me like that call to re.sub should be protected by an > "if:" statement or a "try:" statement. > > Give me a bit of time to look at it. > > OK. I looked. Attached is a quick patch. This patch, in effect, > assumes that it is not an error to have an element was character > content is of type xs:token and the character content is empty. > > I'll look at this more closely, tomorrow. If you try the attached > patch, please tell me what you think. Have I solved the right > problem, for example? Can you think of examples for which this > would not work? > > And, thank you for the error report. > > Dave > >> Thank you and best regards, >> Andrii >> ------------------------------------------------------------------------------ _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users