Hi,
I recently installed pyxb for generating an XML (that conforms to an XSD)
using python bindings (created from the XSD). I've followed
http://pyxb.sourceforge.net/userref_pyxbgen.html for creating the python
bindings and reading an XML for extracting element values, and that has
worked great so far. I'd now like to create an XML using these bindings,
and haven't been able to figure that out using
http://pyxb.sourceforge.net/userref_usebind.html#demo4c
*XML:*
<interfaces>
<interface>
<name>xe-1/0/0</name>
<unit>
<name>0</name>
<family>
<inet>
<address>
<name>10.10.10.1</name>
</address>
</inet>
<inet6>
<address>
<name>2418:a500:2000:10::11/127</name>
</address>
</inet6>
</family>
</unit>
</interface>
</interfaces>
*XSD:*
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="
http://www.w3.org/2001/XMLSchema">
<xs:element name="interfaces" type="InterfacesType"/>
<xs:complexType name="InterfacesType">
<xs:sequence>
<xs:element name="interface" type="InterfaceType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="InterfaceType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="unit" type="UnitType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="UnitType">
<xs:sequence>
<xs:element name="name" type="xs:decimal"/>
<xs:element name="family" type="FamilyType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="FamilyType">
<xs:sequence>
<xs:element name="inet" type="InetType"/>
<xs:element name="inet6" type="Inet6Type"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="InetType">
<xs:sequence>
<xs:element name="address" type="AddressType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Inet6Type">
<xs:sequence>
<xs:element name="address" type="AddressType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
*Validation:*
$xmllint --noout --schema interfaceXSD.xsd interfaceXML.xml
interfaceXML.xml validates
$
*Bindings generated:*
pyxbgen -u interfaceXSD.xsd -m interfaceCreation
*Creating XML from the bindings:*
from __future__ import print_function
import interfaceCreation
import sys
inters = interfaceCreation.interfaces()
print(inters.toxml("utf-8", element_name='interfaces'))
*Errors:*
Traceback (most recent call last):
File "createInterfaceXMLFromXSD.py", line 10, in <module>
print(inters.toxml("utf-8", element_name='interfaces'))
File "/Library/Python/2.7/site-packages/pyxb/binding/basis.py", line
541, in toxml
dom = self.toDOM(bds, element_name=element_name)
File "/Library/Python/2.7/site-packages/pyxb/binding/basis.py", line
513, in toDOM
self._toDOM_csc(bds, element)
File "/Library/Python/2.7/site-packages/pyxb/binding/basis.py", line
2647, in _toDOM_csc
order = self._validatedChildren()
File "/Library/Python/2.7/site-packages/pyxb/binding/basis.py", line
2174, in _validatedChildren
return self.__automatonConfiguration.sequencedChildren()
File "/Library/Python/2.7/site-packages/pyxb/binding/content.py", line
638, in sequencedChildren
cfg = self._diagnoseIncompleteContent(symbols, symbol_set)
File "/Library/Python/2.7/site-packages/pyxb/binding/content.py", line
493, in _diagnoseIncompleteContent
raise pyxb.IncompleteElementContentError(self.__instance, cfg,
symbols, symbol_set)
pyxb.exceptions_.IncompleteElementContentError:
(<interfaceCreation.InterfacesType object at 0x10c291310>,
<pyxb.utils.fac.Configuration object at 0x10c291710>, [], {})
Right now, i'm just trying to create the root element (interfaces), but the
above error pops up everytime.
*If i try to create the next element:*
from __future__ import print_function
import interfaceCreation
import sys
inters = interfaceCreation.interfaces()
inters.interface.name = "ge-1/0/0"
print(inters.toxml("utf-8", element_name='interfaces'))
*get the following error:*
Traceback (most recent call last):
File "createInterfaceXMLFromXSD.py", line 6, in <module>
inters.interface.name = "ge-1/0/0"
AttributeError: 'NoneType' object has no attribute 'name'
I realize this is a basic setup but just can't seem to figure out where the
issue lies after following the examples on pyxb. Would really appreciate
any help.
Thank you.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
pyxb-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyxb-users