[pyxb-users] Unable to generate XML from python classes
Brought to you by:
pabigot
From: Serge G. <ser...@gm...> - 2014-04-16 11:46:45
|
Hi, I am trying to use PyXB (1.2.3) to produce XML from python object. I have a simple xsd schema: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="Items"> <xsd:sequence> <xsd:element name="item" type="Item" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Item"> <xsd:attribute name="name" type="xsd:string" use="required"/> <xsd:attribute name="price" type="xsd:string" use="required"/> </xsd:complexType> <xsd:element name="items" type="Items"/> </xsd:schema> I generated bindings with the command: pyxbgen" -u items.xsd -m items I am able to read an xml (with CreateFromDocument) and get an Items object. Then if try to build the document from python to generate XML, I get an error. I use the following script: import items i1 = items.Item(name="cheese", price="50") i2 = items.Item(name="parrot", price="200") inv = items.Items([i1, i2]) print(inv.tomxl()) Running this script gives me pyxb.exceptions_.MixedContentError: Invalid non-element content Here is the stack trace: Traceback (most recent call last): File "test2.py", line 5, in <module> inv = items.Items([i1, i2]) File "C:\Documents and Settings\sgadioux\Application Data\Python\Python27\site-packages\pyxb\binding\basis.py", line 2060, in __init__ self.extend(args, _from_xml=from_xml, _location=location) File "C:\Documents and Settings\sgadioux\Application Data\Python\Python27\site-packages\pyxb\binding\basis.py", line 2517, in extend [ self.append(_v, _fallback_namespace=_fallback_namespace, _from_xml=_from_xml, _location=_location) for _v in value_list ] File "C:\Documents and Settings\sgadioux\Application Data\Python\Python27\site-packages\pyxb\binding\basis.py", line 2505, in append raise pyxb.MixedContentError(self, value, location) pyxb.exceptions_.MixedContentError: Invalid non-element content What am I doing wrong ? Do I need to specify a namespace in my xsd ? Thanks in advance, Serge |