> From: Aron Griffis > Sent: Thu, April 14, 2011 2:58:12 PM > > > 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. >
Aron - Thanks for that comment. I appreciate the positive feedback. > We've run into three problems which I describe below. For two of > these I have patches, for the third I'm still digging. > I've applied your two patches. See below for a few more comments. > =========================================================================== > > 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: > [snip] > > 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. > valueOf_ should always be a string. If it's not, it would be a good idea if we find out about it and fix it. So ... The only change I made to your first patch is that instead of this: outfile.write(unicode(self.valueOf_).encode(ExternalEncoding)) I used this: outfile.write(self.valueOf_.encode(ExternalEncoding)) Since both plain strings and unicode strings support the .encode() method, I believe that we're OK either way. So, there is no need to create an *extra* unicode string. Do you agree? > =========================================================================== > > Second problem: Given the following XSD: > [snip] > > however "Reason" is its own class because it has the attribute > LocId, so the output we want is this: > [snip] > > 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: Your fix makes sense to me. It works with my tests. So I've applied it. > > =========================================================================== > > 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? > I'll look into this a bit more. But, treating simpleType as a built-in Python type (str, int, etc) is reasonably fundamental to generateDS.py. That's one of the simplifications it does for the user. Still, you're right I suspect, that when a simpleType is used at top level, we need a class. Let me think about it a bit longer. I'll wait before creating a new release, in case we think of a way to solve that 3rd problem. In the meantime, I'm attached my version of generateDS.py with your patches applied in a separate message. > Thanks, You are welcome. And, thank you for your help. Let me know if you have more changes, fixes, suggestiongs, etc. - Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ------------------------------------------------------------------------------ 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