anonynous classes

Help
2013-03-04
2013-03-06
  • John Aherne

    John Aherne - 2013-03-04

    First off, thanks for the project.

    Using pyxbgen I am getting a load of anonymous classes. From another message I see that I can clear this by adding a name tag to the complextype. I have done this and it clears up a number of anonymous classes.

    However my xsd has inner complextypes. If I add a name tag to these, pyxbgen flags up an error :

    Attempt to create non-global complex type definition

    If I do not add the name tag everything generates OK, but I end up with loads of anonymous classes still.

    I am not too well up on XML so any info on what to do about the error would be helpful.

    I have poked around to see what I can find out. And I can get references to the classes but I have to pull out the content via:

    myref.content.CallRef

    etc
    and following the hierarchy down to find other classes and elements.

    This makes me think I have missed some obvious interface to these classes.

    I assume I should be able to access these generated classes more directly, but so far I have missed how I can do that.

    So, any pointers on this would be appreciated.

    I looked at using BIND but thought for the moment it would be easier to amend the xsd to add the name tags. Once I got somewhere with that I would then look more closely at using BIND

    I did try to add some saple xsd and generated code but the post kept on getting rejected as possible spam. So I gave up on that.

    Thanks for any info

    John Aherne

    I amusing python 2.7.3, pyxb 1.2 and Windows 7

     
  • John Aherne

    John Aherne - 2013-03-04

    Sample XSD

    <xs:element name="Defaults">
         <xs:complexType name="Defaultsjah">
        <xs:sequence>
          <xs:element name="Default" minOccurs="0" maxOccurs="unbounded">
              <xs:complexType name="Defaultjah">
            <xs:sequence>
                <xs:element ref="Label" minOccurs="1" maxOccurs="1" />
                <xs:element ref="Value" minOccurs="1" maxOccurs="1" />
                <xs:element ref="Iteration" minOccurs="1" maxOccurs="1" />
            </xs:sequence>
              </xs:complexType>
         </xs:element>
          </xs:sequence>
        </xs:complexType>
    </xs:element>
    

    ____________________

     
  • John Aherne

    John Aherne - 2013-03-04

    Sorry about the excessive posts but I was trying to get some samples up to look at.

    The xsd in the previous post will generate the error "Attempt to create non-global complex type definitio"n when the name tag Defaultjah is used. When that name tag is removed the code is generated.

    Hope that helps to point out where I am going wrong or misunderstanding what to do.

    Thanks

    Joh

     
  • Peter A. Bigot

    Peter A. Bigot - 2013-03-04

    The XML schema language does not permit the name attribute to appear on a complexType that is local to an element declaration.  Only complexType declarations that are at the top level can use the name attribute.  That DefaultJah produces a diagnostic is correct; that DefaultJahs does not is a bug.  (PyXB does not try to validate the schema itself, so it doesn't always get this sort of thing right, and its diagnostics are often opaque.)

    You've probably already found http://pyxb.sourceforge.net/userref_usebind.html#creating-instances-of-anonymous-types.  Your choices in this case are to refactor the schema so that all complex types are defined at the top level and given names that are referenced from the element declarations (which is the approach I recommend, if you control the schema), or to use pyxb.BIND and rely on the content model to infer an appropriate type when assigning values.

     
  • John Aherne

    John Aherne - 2013-03-04

    Thanks for the info.

    I'm a bit green on XML as you may have realised.

    Unfortunately I don't control the schema, so I'll take a closer look at the BIND options and see where that gets me.

    John

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks