Hi Dave, Thanks very much for your swift reply. I will simplify the namespace as you suggested, and move the summary element to the top of the schema.
As it is the only defined element, I was hoping the code would automatically pick it up. With regard to a simpleType of another simpleType, this is actually one of the examples on the w3 website, which I shamelessly copied. I look forward to your fix for this issue, so I can start using my full schema. In the mean time I will play around with the classes in python to get a feel for the objects created. Thanks, Rob --------------------------------- Robert Lambert Imperial College, London High Energy Physics Rm. 528, Blackett Laboratory, Tel: +44 (0)207 594 7815 Fax: +44 (0)207 823 8830 Email: r.lamb...@imperial.ac.uk --------------------------------- LHCb RICH CERN 2-1-016 Tel: +41 (0)22 767 3504 --------------------------------- ________________________________________ From: Dave Kuhlman [dkuhl...@rexx.com] Sent: 23 June 2009 23:59 To: Lambert, Rob Cc: generateds-users@lists.sourceforge.net Subject: Re: Cannot parse my XML with generateDS > Dear Dave, > > I have a problem using the generateDS.py tool with python v2.5.4. > (no lxml) > > Please forgive me as this is the first time I'm truly coding in > XML, but I'm a long-term python user. I'd really like to use your > tool, which will be incorporated into our experimental software for > LHCb. > > I am trying to create the code from the xsd you will find in the > attached file. > > I get a very useless error: > > line 4026 > "NoneType object has no attribute 'annotate'" > Perhaps I've got the options wrong? > > I have tried many possible combinations of options. > Maybe you can help? You are right. That's a very uninformative error message. Sigh. But, I've never been able to make it better. If you have a suggestion, please pass it along. With respect to your specific problem, generateDS.py expects a specific namespace prefix ("xs:") to be used in the XML Schema file, and it is not very smart about figuring out what the namespace prefix is when it differs from "xs:". In your case, the schema has no namespace prefix. So, I was able to parse your schema with the following command: $ ./generateDS.py -a "" -f --super=tmp1sup -o tmp1sup.py -s tmp1sub.py XMLSummary.xsd That's the easy way to fix it. But, in the future, I'd suggest that you use a namespace prefix, for example "xs:, in your schemas". Here is an example cut from your schema and modified: <xs:simpleType name="CollapsedString"> <xs:restriction base="string"> <xs:whiteSpace value="collapse"/> </xs:restriction> </xs:simpleType> And, if you use a different namespace prefix, then use the -a option. There's a little bit in the documentation about this, although I have to admit, even I feel it's unlikely that users will find it: http://www.rexx.com/~dkuhlman/generateDS.html#namespace-prefix-mis-match By the way, when I generate code from your schema, the generated parsing methods (parse(), parseString(), ...) assume that Memory is the top level element in your XML instance documents, whereas I believe (from comments in your schema) that summary (SummaryType) is the root element. So, you could consider using this command line option: --root-element="SummaryType" or, alternatively, move the following line to the top of your schema: <element name="summary" type="lhcb:SummaryType"/> generateDS.py assumes that the first element it encounters is the root element unless that --root-element option is used. A bug and a word of thanks -- Your example exposed an error. But, I have not found a solution for this one yet. In your XML Schema, you have a simpleType that is a restriction on another simpleType. Cool. I had never tried that. But, generateDS.py does not handle it. So, for the time being, you will have to modify your schema, and change the definitions of StepType and FileStatus so that following: <simpleType name="CollapsedString"> <restriction base="string"> <whiteSpace value="collapse"/> </restriction> </simpleType> <simpleType name="StepType"> <restriction base="lhcb:CollapsedString"> <enumeration value="none"/> <enumeration value="initialize"/> <enumeration value="execute"/> <enumeration value="finalize"/> </restriction> </simpleType> <simpleType name="FileStatus"> <restriction base="lhcb:CollapsedString"> <enumeration value="none"/> <enumeration value="fail"/> <enumeration value="part"/> <enumeration value="full"/> </restriction> </simpleType> becomes: <simpleType name="CollapsedString"> <restriction base="string"> <whiteSpace value="collapse"/> </restriction> </simpleType> <simpleType name="StepType"> <restriction base="string"> <enumeration value="none"/> <enumeration value="initialize"/> <enumeration value="execute"/> <enumeration value="finalize"/> </restriction> </simpleType> <simpleType name="FileStatus"> <restriction base="string"> <enumeration value="none"/> <enumeration value="fail"/> <enumeration value="part"/> <enumeration value="full"/> </restriction> </simpleType> Basically, it is ignoring the CollapsedString type. I've attached the modified version of XMLSummary.xsd from which I was able to generate and parse your sample instance docs. Also, I've attached my latest version of generateDS.py, in case yours is different. I'll be uploading this version as soon as I can do a bit more testing. And, here are the commands I used to do it: $ ./generateDS.py -f -a "" --super=tmp2sup -o tmp2sup.py -s tmp2sub.py XMLSummary02.xsd $ python tmp2sub.py Summary_Minimal.xml Hope this helps. I'll be looking into the problem related to the simpleType whose base is another simpleType, but don't know when or if I'll be able to solve it. I'll let you know when I do. I've CC'ed the generateds-users email list, because this discussion might be of interest and helpful to other users. - Dave ------------------------------------------------------------------------------ _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users