Hi Dave, Thanks for generateDS. It's been doing a good job for us! We were using 1.20f for a long time and recently updated to 2.4c.
We've run into three problems which I describe below. For two of these I have patches, for the third I'm still digging. =========================================================================== First problem: UnicodeEncodeError when exporting. Most of the calls to outfile.write() honor ExternalEncoding but one of them doesn't, and that causes a UnicodeEncodeError when Python tries to use default 7-bit ASCII. Here's the patch I'm using: diff --git a/generateds/generateDS.py b/generateds/generateDS.py --- a/generateds/generateDS.py +++ b/generateds/generateDS.py @@ -1787,7 +1787,7 @@ s1 = " outfile.write('>')\n" wrt(s1) if not element.isMixed(): - s1 = " outfile.write(self.valueOf_)\n" + s1 = " outfile.write(unicode(self.valueOf_).encode(ExternalEncoding))\n" wrt(s1) else: s1 = " outfile.write('>\\n')\n" I wrapped self.valueOf_ in unicode() just in case it can ever be a non-string; casting it ensures that the encode method will be available, and it's a noop if self.valueOf_ is already a unicode object. =========================================================================== Second problem: Given the following XSD: <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns="http://www.hp.com/schemas/foo/2009/12/20" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.hp.com/schemas/foo/2009/12/20" elementFormDefault="qualified" version="1"> <xs:element name="Reasons"> <xs:complexType> <xs:sequence> <xs:element name="Reason" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="ReasonsEnum"> <xs:attribute name="LocId" type="xs:string"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:simpleType name="ReasonsEnum"> <xs:restriction base="xs:NMTOKEN"> <xs:enumeration value="foo"/> <xs:enumeration value="bar"/> <xs:enumeration value="baz"/> </xs:restriction> </xs:simpleType> </xs:schema> The generated output contains: class Reasons(GeneratedsSuper): ... def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): if nodeName_ == 'Reason': obj_ = None self.Reason.append(obj_) however "Reason" is its own class because it has the attribute LocId, so the output we want is this: class Reasons(GeneratedsSuper): ... def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): if nodeName_ == 'Reason': obj_ = Reason.factory() obj_.build(child_) self.Reason.append(obj_) Presently I'm fixing this with the following patch, but I don't know if it could cause problems elsewhere: diff --git a/generateds/generateDS.py b/generateds/generateDS.py --- a/generateds/generateDS.py +++ b/generateds/generateDS.py @@ -2676,9 +2676,7 @@ wrt(s1) # Is this a simple type? base = child.getBase() - if (child.getSimpleType() or - (base and base in SimpleTypeDict) - ): + if child.getSimpleType(): s1 = " obj_ = None\n" wrt(s1) else: =========================================================================== Third problem: Given the following XSD: <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns="http://www.hp.com/schemas/bar/2009/12/20" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.hp.com/schemas/bar/2009/12/20" elementFormDefault="qualified" version="1"> <xs:element name="bar" type="barType"/> <xs:simpleType name="barType"> <xs:restriction base="xs:token"> <xs:enumeration value="foo"/> <xs:enumeration value="bar"/> <xs:enumeration value="baz"/> </xs:restriction> </xs:simpleType> </xs:schema> I need to be able to instantiate and export a "bar" object, but the generated file doesn't contain any classes. I think the problem here is that normally generateDS represents simple elements as primitive Python values in the XML tree, but we need a class when the element appears at the top level. I noted there's an array called topLevelSimpleTypes which is maybe related to this, but it doesn't seem to be fully implemented. Any ideas? Thanks, Aron ------------------------------------------------------------------------------ Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users