1

I am trying to create a pyxb module from the LabVIEW schema. Using the module I am getting an UnrecognizedDOMRootNodeError:

Traceback (most recent call last):
File "X:\Projects\LV-PY\Python\LV-PY\pyXB\testXML.py", line 14, in <module>
  fc_return = cluster.CreateFromDOM(doc.documentElement)
File "X:\Projects\LV-PY\Python\LV-PY\pyXB\cluster.py", line 76, in 
 CreateFromDOM
return pyxb.binding.basis.element.AnyCreateFromDOM(node, default_namespace)
File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 1743, in 
 AnyCreateFromDOM
return cls.CreateDOMBinding(node, expanded_name.elementBinding(), 
    _fallback_namespace=fallback_namespace)
File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 1705, in   
    CreateDOMBinding
raise pyxb.UnrecognizedDOMRootNodeError(node)
   pyxb.exceptions_.UnrecognizedDOMRootNodeError: <pyxb.utils.saxdom.Element
   object at 0x0625F9D0>

Since the LabVIEW schema is huge, I made a small sample of it with just a Cluster containing a string:

<xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:lv="http://www.ni.com/labview" elementFormDefault="qualified"
targetNamespace="http://www.ni.com/labview"
xmlns="http://www.ni.com/labview">

<!--Root element that contains all other data-->
<!--will NOT be produced by primitive-->
<xsd:element name="LVData" type="lv:LVDataRootType"/>
<xsd:complexType name="LVDataRootType">
  <xsd:choice minOccurs="0" maxOccurs="unbounded">
    <xsd:element name="Cluster" type="lv:ClusterType"/>
    <xsd:element name="String" type="lv:StringType"/>
  </xsd:choice>
</xsd:complexType>

<!--Basic elements-->

<xsd:complexType name="StringType">
  <xsd:complexContent>
    <xsd:extension base="lv:LVDataType"/>
   </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="LVDataType">
    <xsd:sequence>
        <xsd:element name="Name" type="xsd:string" minOccurs="1"/>
        <xsd:element name="Val" type="xsd:string" minOccurs="1"/>
    </xsd:sequence>
</xsd:complexType>

<!--Cluster element-->
<xsd:complexType name="ClusterType">
  <xsd:sequence>  
      <xsd:element name="Name" type="xsd:string"/>
      <xsd:element name="NumElts" type="xsd:unsignedByte"/>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="String" type="lv:StringType"/>
        </xsd:choice>
   </xsd:sequence>
</xsd:complexType>

</xsd:schema>

Then I sent the XML output from a simple LabVIEW cluster:

<Cluster>
<Name>clTest</Name>
<NumElts>1</NumElts>
<String>
<Name>sTest</Name>
<Val>foo</Val>
</String>
</Cluster>

I'm guessing the problem is related to pabigot's reply from: a similar question

in XML Schema namespaces for elements and types are distinct, but in Python they are not,

But I'm not so sure. Do I need to change the lv:...Type throughout the LabView Schema to have the same name and type?

In other words, rather than:

    <xsd:element name="Cluster" type="lv:ClusterType"/>

should I have:

    <xsd:element name="Cluster" type="Cluster"/>

This would be a major change to the LabVIEW schema, which does this sort of thing throughout.

Community
  • 1
  • 1

1 Answers1

0

There are two problems with your document. The schema expects a top-level element {http://www.ni.com/labview}LVData, while your document has a top-level element Cluster. You need to wrap your document, and add a namespace declaration. The document below does not produce an error.

<LVData xmlns="http://www.ni.com/labview">
  <Cluster>
    <Name>clTest</Name>
    <NumElts>1</NumElts>
    <String>
      <Name>sTest</Name>
      <Val>foo</Val>
    </String>
  </Cluster>
</LVData>
pabigot
  • 989
  • 7
  • 8