我使用模式文件 (.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 element_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)
一切正常。那么我做错了什么?