This isn't a PyXB issue. Your schema extract only allows for a single
Employee element with a single Address element. You're going to need to
use maxOccurs="unbounded" or some similar directive in the schema
definition.
Peter
On Fri, Apr 3, 2015 at 9:14 AM, Ajinkya Fotedar <ajinkyafote...@gmail.com>
wrote:
> 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.
>
>
> ------------------------------------------------------------------------------
> 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
> pyxb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyxb-users
>
>
------------------------------------------------------------------------------
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
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users