Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python <;元素>;没有开始标记的绑定元素_Python_Xml_Schema_Pyxb - Fatal编程技术网

Python <;元素>;没有开始标记的绑定元素

Python <;元素>;没有开始标记的绑定元素,python,xml,schema,pyxb,Python,Xml,Schema,Pyxb,我使用一个模式文件(.xsd)来生成用于生成xml代码的python类。 我可以使用所有生成的计算,但如果我尝试 print d.toxml("utf-8") File "/usr/local/lib/python2.7/dist-packages/pyxb/binding/basis.py", line 541, in toxml dom = self.toDOM(bds) File "/usr/local/lib/python2.7/dist-packages/pyxb/bi

我使用一个模式文件(.xsd)来生成用于生成xml代码的python类。 我可以使用所有生成的计算,但如果我尝试

print d.toxml("utf-8")
  File "/usr/local/lib/python2.7/dist-packages/pyxb/binding/basis.py", line 541, in toxml
    dom = self.toDOM(bds)
  File "/usr/local/lib/python2.7/dist-packages/pyxb/binding/basis.py", line 513, in toDOM
    raise pyxb.UnboundElementError(self)
pyxb.exceptions_.UnboundElementError: Instance of type visionDataPackage has no bound element for start tag
结果是缺少元素的element_name属性。因此,如果我在/usr/local/lib/python2.7/dist-packages/pyxb/binding/basis.py元素_name中设置:

    element_name="visionDataPackage"
    if (element_name is None) and (self._element() is not None):
        element_binding = self._element()
        element_name = element_binding.name()
        need_xsi_type = need_xsi_type or element_binding.typeDefinition()._RequireXSIType(type(self))
    if element_name is None:
        raise pyxb.UnboundElementError(self)
一切正常。
那么我做错了什么呢?

可能您正在使用它的类型而不是元素创建
d
。例如,如果您的模式具有:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="atype">
    <xs:sequence>
      <xs:element name="entry" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  <xs:element name="anelt" type="atype"/>
</xs:schema>

如果您要执行
d=atype()
,则
d
不会绑定到任何元素。如果改用
d=anelt()
,则
d
仍将是
atype
的实例,但它将绑定到
anelt
。正是这种绑定告诉PyXB在从对象生成DOM或文本XML表示时要使用什么元素标记

在PyXB 1.2.3中发现并修复了PyXB以前分配的默认元素标记,该标记是在对象未绑定到元素时从基础类型推断出来的

请参阅有关的其他讨论