Re: [Generateds-users] Token element with zero occurrences
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 >> >> >> 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
Re: [Generateds-users] Token element with zero occurrences
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 > > > 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 > -- Dave Kuhlman http://www.davekuhlman.org diff -r d7d1913e027f generateDS.py --- a/generateDS.py Wed Sep 14 11:27:07 2016 -0700 +++ b/generateDS.py Thu Sep 22 12:49:53 2016 -0700 @@ -3590,8 +3590,11 @@ else: wrt("%s_ = child_.text\n" % name) if childType == TokenType: -wrt('%s_ = re_.sub(' +wrt('if %s_:\n' % (name, )) +wrt('%s_ = re_.sub(' 'String_cleanup_pat_, " ", %s_).strip()\n' % (name, name)) +wrt('else:\n') +wrt('%s_ = ""\n' % (name, )) if child.isListType(): if (childType in IntegerType or childType == PositiveIntegerType or -- ___ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users
[Generateds-users] Token element with zero occurrences
Dear Dave, I am experiencing the following issue: I try to generate the structure with an element 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? Thank you and best regards, Andrii -- ___ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users