pyxb UnrecognizedDOMRootNodeError
Question: i've got the following xml schema:

    
    
    <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
    <xsd:complexType name="DataPackage">
        <xsd:sequence>
            <xsd:element name="timestamp" type="xsd:float" default="0.0"/>
            <xsd:element name="type" type="xsd:string" default="None"/>
            <xsd:element name="host" type="xsd:string" default="None"/>
            <xsd:element name="data" type="Data" />
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="Data">
        <xsd:sequence>
            <xsd:element name="item" type="Item" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="Item">
        <xsd:sequence>
            <xsd:element name="key" type="xsd:string"/>
            <xsd:element name="val" type="xsd:string"/>
        </xsd:sequence>
     </xsd:complexType>
    
    </xsd:schema>
    

I used `pyxbgen -u DataPackage.xsd -m DataPackage` to generate the
corresponding python classes and used these to generate the following xml
code:

    
    
    <?xml version="1.0" encoding="utf-8"?>
    <DataPackage>
    <timestamp>1378970933.29</timestamp>
    <type>None</type>
    <host>Client 1</host>
    <data>
        <item>
            <key>KEY1</key>
            <val>value1</val>
        </item>
    </data>
    </DataPackage>
    

If i try to read this using the following in python interpreter:

    
    
    import DataPackage
    xml = file("dataPackage-Test.xml").read()
    data = DataPackage.CreateFromDocument(xml)
    

I get the exception:

    
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "DataPackage.py", line 54, in CreateFromDocument
        instance = handler.rootObject()
      File "/usr/local/lib/python2.7/dist-packages/pyxb/binding/saxer.py", line 274, in   rootObject
        raise pyxb.UnrecognizedDOMRootNodeError(self.__rootObject)
    pyxb.exceptions_.UnrecognizedDOMRootNodeError: <pyxb.utils.saxdom.Element object at  0x9c7c76c>
    

Anyone an idea what's wrong?


Answer: Your schema defines a top-level complex type named DataPackage, but does not
define any top-level elements. Thus the DOM element DataPackage has no
corresponding element that PyXB can use to process it.

You need to add something like:

    
    
    <element name="DataPackage" type="DataPackage"/>
    

Note that in XML Schema the namespaces for elements and types are distinct,
but in Python they are not, so PyXB will rename one of them (the complex type
in this case) to avoid the conflict. See
<http://pyxb.sourceforge.net/arch_binding.html?highlight=conflict#deconflicting-
names>

