[pyxb-users] Issues generating an XML with multiple complexType instances using BIND and/or append
Brought to you by:
pabigot
From: Ajinkya F. <aji...@gm...> - 2015-04-03 14:14:12
|
I'd like to have multiple instances of complexTypes in an XML created from the bindings. Not sure if/how this can be done using BIND and/or append. Will try and explain with an example i'm playing with. *XML Schema…* <xs:schema elementFormDefault="qualified" xmlns:xs=" http://www.w3.org/2001/XMLSchema"> <xs:element name="Organization" type="OrganizationType"/> <xs:complexType name="OrganizationType"> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Employee" type="EmployeeType"/> </xs:sequence> </xs:complexType> <xs:complexType name="EmployeeType"> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Address" type="AddressType"/> </xs:sequence> </xs:complexType> <xs:complexType name="AddressType"> <xs:sequence> <xs:element name="Street" type="xs:string"/> <xs:element name="Town" type="xs:string"/> <xs:element name="County" type="xs:string"/> <xs:element name="PostCode" type="xs:integer”/> <xs:element name="Country" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema> *Used the above schema for generating bindings…* pyxbgen -u organization.xsd -m organization *Used the ‘organization’ module for generating an xml...* import organization import pyxb org = organization.Organization() org.Employee = pyxb.BIND() org.Employee.Address = pyxb.BIND() org.Name = 'company1’ org.Employee.Name = 'name1’ org.Employee.Address.Street = 'street1’ org.Employee.Address.Town = 'town1’ org.Employee.Address.County = 'county1’ org.Employee.Address.PostCode = 54545 org.Employee.Address.Country = 'US' print (org.toxml('utf-8', element_name='Organization')) *Output…* <Organization> <Name>company1</Name> <Employee> <Name>name1</Name> <Address> <Street>street1</Street> <Town>town1</Town> <County>county1</County> <PostCode>54545</PostCode> <Country>US</Country> </Address> </Employee> </Organization> *What i'd like the o/p to be…* <Organization> <Name>company1</Name> <Employee> <Name>name1</Name> <Address> <Street>street1</Street> <Town>town1</Town> <County>county1</County> <PostCode>54545</PostCode> <Country>US</Country> </Address> <Address> <Street>street2</Street> <Town>town2</Town> <County>county2</County> <PostCode>77777</PostCode> <Country>US</Country> </Address> </Employee> </Organization> *OR…* <Organization> <Name>company1</Name> <Employee> <Name>name1</Name> <Address> <Street>street1</Street> <Town>town1</Town> <County>county1</County> <PostCode>54545</PostCode> <Country>US</Country> </Address> </Employee> <Employee> <Name>name2</Name> <Address> <Street>street2</Street> <Town>town2</Town> <County>county2</County> <PostCode>45454</PostCode> <Country>UK</Country> </Address> </Employee> </Organization> Would really appreciate if any one here could point me to the right direction. I believe BIND and append/extend will do the job. I have tried them from this link http://sourceforge.net/p/pyxb/discussion/956708/thread/c3da791a/#922f but nothing has worked out so far. Thank you. |