Hi, Dave,

Thanks for your reply.

Sorry, I think I might not be quite specific in describing the issue I
encountered.

Actually, I mean, in the below xsd:

<xs:complexType name="TEntityType">
    <xs:sequence>
      <xs:element name="Documentation" type="edm:TDocumentation"
minOccurs="0" maxOccurs="1" />
      <xs:element name="Key" type="edm:TEntityKeyElement"
minOccurs="0" maxOccurs="1" />      <xs:choice minOccurs="0"
maxOccurs="unbounded">
        <xs:element name="Property" type="edm:TEntityProperty"
minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="NavigationProperty"
type="edm:TNavigationProperty" minOccurs="0" maxOccurs="unbounded" />
      </xs:choice>
      <xs:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attributeGroup ref="edm:TDerivableTypeAttributes" />
    <xs:attribute ref="cg:TypeAccess" use="optional" />
    <xs:anyAttribute namespace="##other" processContents="lax" />
  </xs:complexType>

For TEntityType python class, the corresponding python class code should
have a get_NavigationProperty(self) method generated, as what is has done
for get_Property(self) method, but it isn't the case.

I confirm that the class for TNavigationProperty is well generated in my
output python code.

The below is the code generated for TEntityType , use can see that
get_NavigationProperty(self) methos is missing:

class TEntityType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Name=None, Documentation=None, Key=None,
Property=None, anytypeobjs_=None):
        self.original_tagname_ = None
        self.Name = _cast(None, Name)
        self.Documentation = Documentation
        self.Key = Key
        if Property is None:
            self.Property = []
        else:
            self.Property = Property
        if anytypeobjs_ is None:
            self.anytypeobjs_ = []
        else:
            self.anytypeobjs_ = anytypeobjs_
        self.anyAttributes_ = {}
    def factory(*args_, **kwargs_):
        if TEntityType.subclass:
            return TEntityType.subclass(*args_, **kwargs_)
        else:
            return TEntityType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Documentation(self): return self.Documentation
    def set_Documentation(self, Documentation): self.Documentation =
Documentation
    def get_Key(self): return self.Key
    def set_Key(self, Key): self.Key = Key
    def get_Property(self): return self.Property
    def set_Property(self, Property): self.Property = Property
    def add_Property(self, value): self.Property.append(value)
    def insert_Property_at(self, index, value): self.Property.insert(index,
value)
    def replace_Property_at(self, index, value): self.Property[index] =
value
    def get_anytypeobjs_(self): return self.anytypeobjs_
    def set_anytypeobjs_(self, anytypeobjs_): self.anytypeobjs_ =
anytypeobjs_
    def add_anytypeobjs_(self, value): self.anytypeobjs_.append(value)
    def insert_anytypeobjs_(self, index, value): self._anytypeobjs_[index]
= value
    def get_Name(self): return self.Name
    def set_Name(self, Name): self.Name = Name
    def get_anyAttributes_(self): return self.anyAttributes_
    def set_anyAttributes_(self, anyAttributes_): self.anyAttributes_ =
anyAttributes_


Regards

Nan


On Fri, Jun 5, 2015 at 2:35 AM, Dave Kuhlman <dkuhl...@davekuhlman.org>
wrote:

> On Tue, Jun 02, 2015 at 11:36:19PM +0800, Huang, Nan wrote:
> > Today I tried to work with generatedDS for my OData related project, we
> > have a XSD file in hands, and tried to generated the corresponding python
> > model for it, but we encountered an issue regarding a missing element in
> > the generated python code. We tried with the latest 2.16a0, and older
> ones,
> > 2.14a, 2,4c, all of them have the same issue.
> >
> > The XSD we tried to use is here:
> > https://msdn.microsoft.com/en-us/library/hh879817.aspx
> >
> > You can see that in this xsd, there is a section:
> >
> > <xs:complexType name="TEntityType">
> >     <xs:sequence>
> >       <xs:element name="Documentation" type="edm:TDocumentation"
> > minOccurs="0" maxOccurs="1" />
> >       <xs:element name="Key" type="edm:TEntityKeyElement"
> > minOccurs="0" maxOccurs="1" />      <xs:choice minOccurs="0"
> > maxOccurs="unbounded">
> >         <xs:element name="Property" type="edm:TEntityProperty"
> > minOccurs="0" maxOccurs="unbounded" />
> >         <xs:element name="NavigationProperty"
> > type="edm:TNavigationProperty" minOccurs="0" maxOccurs="unbounded" />
> >       </xs:choice>
> >       <xs:any namespace="##other" processContents="lax" minOccurs="0"
> > maxOccurs="unbounded" />
> >     </xs:sequence>
> >     <xs:attributeGroup ref="edm:TDerivableTypeAttributes" />
> >     <xs:attribute ref="cg:TypeAccess" use="optional" />
> >     <xs:anyAttribute namespace="##other" processContents="lax" />
> >   </xs:complexType>
> >
> > In the <xs:choice> element, there are two sub-elements, Property and
> > NavigationProperty. But in the generated code, we found only Property
> > under TEntityType, no NavigationProperty.
>
> Nan Huang,
>
> Thanks for your report.  Your description of the problem was very
> helpful in trying to reproduce the problem.
>
> I've generated code using the XML schema you referred to.  I also
> searched for, found, and downloaded a schema imported by that one.
> The schemas I'm using are at these locations:
>
> - https://msdn.microsoft.com/en-us/library/hh879817.aspx
> -
> https://code.google.com/p/edmx/source/browse/trunk/Source/Edmx/Schema/System.Data.Resources.CodeGenerationSchema.xsd
>
> I've attached those schemas to this message in case you want to
> compare them with yours.
>
> The code I generated contains definitions of classes TEntityProperty
> and TNavigationProperty.  And in method buildChildren in class
> TEntityType, it builds Property as an instance of class
> TEntityProperty and it builds NavigationProperty as an instance of
> class TNavigationProperty.  It also looks like they are both being
> exported in method exportChildren of class TEntityType.
>
> That all seems correct to me.
>
> So, which is the piece that is missing?
>
> I've attached the file that I generated (tmp01sup.py) so that you
> can check to see whether it contains something that is missing in
> that files that you generate.
>
> You can look at the top of that generated file to see the command
> line and options that I used to generate this file.  I also tried it
> with other/fewer options and got similar results.
>
> I appologize for being a bit slow to see this problem.  Perhaps you
> can tell me more specifically what is missing.
>
> I'm using generateDS.py 2.16a.  That's the same as 2.16a0.  For some
> reason, setuptools (or whatever it is) added the zero when I
> uploaded that version to the Python Package Index.
>
> >
> > Is this a bug or we miss-used the library? We simply used the -o
> > option in your tutorial.
> >
> > BTW, in recent version, we only support lxml instead of both lxml and
> > ET in generated code, this is a bit inconvenient as lxml is platform
> > dependent and need native library, and we cannot continue to have a
> > single pure python dist for all platforms.
>
> As I recall, I had problems with ElementTree at one point.  It had
> something to do with namespaces and namespace prefixes in
> process_includes.py (which is imported by generateDS.py.  My belief
> is that ElementTree is pretty strong in its support of namespaces,
> so we can wonder about whether that was my mistake.
>
> It is possible, maybe even likely, that you can patch the generated
> file so that it uses ElementTree instead of Lxml.  You could even
> patch generateDS.py itself so that it produces files that use
> ElementTree instead of Lxml.  It would require changing just a few
> lines of boiler plate, after all.  Here is a diff that will give you
> an idea of what to change:
>
>     --- tmp26sup.py 2015-06-04 11:15:02.236588923 -0700
>     +++ test01.py   2015-06-04 11:17:36.094327799 -0700
>     @@ -31,18 +31,14 @@
>      import base64
>      import datetime as datetime_
>      import warnings as warnings_
>     -from lxml import etree as etree_
>     +from xml.etree import ElementTree as etree_
>
>
>      Validate_simpletypes_ = True
>
>
>      def parsexml_(infile, parser=None, **kwargs):
>     -    if parser is None:
>     -        # Use the lxml ElementTree compatible parser so that, e.g.,
>     -        #   we ignore comments.
>     -        parser = etree_.ETCompatXMLParser()
>     -    doc = etree_.parse(infile, parser=parser, **kwargs)
>     +    doc = etree_.parse(infile, **kwargs)
>          return doc
>
> There may be features that require Lxml in the generated code.  But,
> if your use case does not use those features, ElementTree might work
> for you.  You will have to do testing yourself to find out.
>
> If that works, at least your users will not need to install Lxml,
> even though you (or whoever generates the code) will still need
> Lxml.
>
> Hope this helps.
>
> Dave
>
> >
> > Regards
> >
> > Nan Huang
>
> --
>
> Dave Kuhlman
> http://www.davekuhlman.org
>
------------------------------------------------------------------------------
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to