Dear Dave and all,I have a peculiar use-case I would like to explain you in order to suggest a possible improvement of generateDS (that would be very useful to me).
In attachment you find an XSD schema (package.xsd), an example of XML instance (skycat_example.xml), an originally generateDS generated file (orig.package.py) and the same file modified by me (package.py).
Well, as you can easily see, in skycat_example.xml there is an element named <parameter> that has got the special attribute xsi:type="uri". This because <parameter> is of parameterType type which is an abstract type with many different implementations like, for instance, <uri> (in this case).
When generateDS creates the data structure for <parameter> element, it is not able to recognize its type (I guess), and then treats it as a string, failing to create a suitable class structure.
So, what basically I did was to modify the parameter.build method like this: def build(self, node_): attrs = node_.attributes for item in attrs.itemsNS(): if item[0][0] == "http://www.w3.org/2001/XMLSchema-instance" and \ item[0][1] == 'type': type = item[1] break self.type = eval("%s()" % type) self.type.build(node_) and the parent class buildChildren method like this: def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'group': obj_ = group.factory() obj_.build(child_) self.group.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'parameter': obj_ = parameter.factory() obj_.build(child_) self.parameter.append(obj_.type) Here below the complete set of changes: --- orig.package.py 2008-10-22 15:37:01.000000000 +0200 +++ package.py 2008-10-22 15:34:05.000000000 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# Generated Wed Oct 22 15:37:01 2008 by generateDS.py. +# Generated Wed Oct 22 15:09:12 2008 by generateDS.py. # import sys @@ -775,8 +775,7 @@ class psetdefType(object): for group_ in self.get_group(): group_.export(outfile, level, namespace_, name_='group') for parameter_ in self.get_parameter(): - showIndent(outfile, level)- outfile.write('<%sparameter>%s</%sparameter>\n' % (namespace_, quote_xml(parameter_), namespace_)) + parameter_.export(outfile, level, namespace_, name_='parameter')
def exportLiteral(self, outfile, level, name_='psetdefType'): level += 1 self.exportLiteralAttributes(outfile, level, name_) @@ -802,7 +801,10 @@ class psetdefType(object): level += 1 for parameter in self.parameter: showIndent(outfile, level) - outfile.write('%s,\n' % quote_python(parameter)) + outfile.write('parameter(\n') + parameter.exportLiteral(outfile, level) + showIndent(outfile, level) + outfile.write('),\n') level -= 1 showIndent(outfile, level) outfile.write('],\n') @@ -823,10 +825,10 @@ class psetdefType(object): self.group.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'parameter': - parameter_ = '' - for text__content_ in child_.childNodes: - parameter_ += text__content_.nodeValue - self.parameter.append(parameter_) + obj_ = parameter.factory() + obj_.build(child_) + self.parameter.append(obj_.type) + # end class psetdefType @@ -865,11 +867,13 @@ class parameter(object): outfile.write('valueOf_ = "%s",\n' % (self.valueOf_,)) def build(self, node_): attrs = node_.attributes - self.buildAttributes(attrs) - self.valueOf_ = '' - for child_ in node_.childNodes: - nodeName_ = child_.nodeName.split(':')[-1] - self.buildChildren(child_, nodeName_) + for item in attrs.itemsNS():+ if item[0][0] == "http://www.w3.org/2001/XMLSchema-instance" and \
+ item[0][1] == 'type': + type = item[1] + break + self.type = eval("%s()" % type) + self.type.build(node_) def buildAttributes(self, attrs): pass def buildChildren(self, child_, nodeName_): @@ -4108,7 +4112,7 @@ def parseLiteral(inFileName): rootObj.build(rootNode) # Enable Python to collect the space used by the DOM. doc = None - sys.stdout.write('from orig.package import *\n\n') + sys.stdout.write('from package import *\n\n') sys.stdout.write('rootObj = package(\n') rootObj.exportLiteral(sys.stdout, 0, name_="package") sys.stdout.write(')\n')I have tried to put my dirty hands in generateDS code in order to make it supporting this peculiar case, but I didn't succeed. Please, can you give me a hint or help me to improve generateDS in this direction?
Thanks in advance. Luigi -- Luigi Paioro INAF - IASF Milano Via Bassini 15, I-20133 Milano, Italy Phone (+39) 02 23 699 470 Fax (+39) 02 26 660 17 Site http://www.iasf-milano.inaf.it/luigi/
package.tar.gz
Description: GNU Zip compressed data
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users