From: Vincent van Beveren <v.vanbeve...@rijnhuizen.nl> To: Dave Kuhlman <dkuhl...@pacbell.net> Sent: Tuesday, February 10, 2009 11:28:07 PM Subject: RE: [Generateds-users] FW: Couple of issues writing XML
> Hi Dave, > > Thanks for your reply. Vincent - I've created a schema and an instance document that tries to test several of the problems you've identified. I've attached the following: - My current working copy of generateDS.py. - An XML Schema (data_schema_1.xsd) - The code generated by generateDS.py from the XML Schema (tmp3sup.py and tmp3sub.py). - An XML instance document used as input (data_input_1.xml) - An XML instance document that is the result of running the generated code (data_output_1.xml) Here is how I ran it: $ ./generateDS.py -f --super=tmp3sup -o tmp3sup.py -s tmp3sub.py data_schema_1.xsd $ python tmp3sub.py data_input_1.xml > > As far as I am concerned, an element may > only be represented as <x /> when it may not contain any children, and no > character data. In any other case it is alright for me that it prints > <x></x>. The attached files have these test cases. Just to make sure, I believe that you are saying that instead of lines 3 and 4: <item ident="1"> </item> export should actually produce this: <item ident="1" /> Is that right? I'll start working on it. The attached examples exposed another problem, I'm afraid. This: <testvalue></testvalue> should not have been exported, right? > > Another thing to look at (from the java > perspective) is JAXB, which is almost exactly what generateDS does. Actually I > was more familiar with Java then with Python before I started working on this > project, and search for something similar to JAXB, when I found generateDS. > > The attribute story is more about default python > values when I do not specify them in the XSD. For example: It seems to me that the omitted values are handled correctly. When a value is omitted, the generated code does not export the attribute. Am I right about this? Is the attached code doing what we want? Is it possible that you are using an older version of generateDS.py? Thanks for the suggestion about JAXB. I knew about XMLBeans, but not JAXB. I'll take a look. By the way, I don't know whether you have looked at Jython. The Java code generated by XMLBeans is usable by Jython. I suspect that Jython could also import and use the code generated by JAXB. Not trying to talk you out of using generateDS.py, but in a more Java oriented environment or shop, ... More later. - Dave > > <?xml version="1.0"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";> > <xs:element name="Test"> > <xs:complexType> > <xs:attribute name="integer" type="xs:int" use="optional" /> > </xs:complexType> > </xs:element> > </xs:schema> > > Would generate the following constructor: > > classTest(object): > subclass = None > superclass = None > def__init__(self, integer=-1, valueOf_=''): > self.integer > = integer > self.valueOf_ > = valueOf_ > > Note that the integer is initialized to -1 > > When the exportAttribute is ddefined as > followed: > > defexportAttributes(self, outfile, level, namespace_='', name_='Test'): > ifself.get_integer() isnotNone: > outfile.write(' integer="%d"'% self.get_integer()) > > Note that it does not check for -1, but > for None. This would mean that if I do not specify the attribute, that it > would > render it as integer=”-1”, while the desired output is that it does > not render the attribute at all. This would be fixed if the integer would be > initialized to None. > > Regards, > Vincent > -- Dave Kuhlman http://www.rexx.com/~dkuhlman ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users