[xsd-users] keep sequence order in C++ while using xs:choice in XSD

Alexey Glotov Alexey.Glotov at samtec.de
Thu May 27 11:24:37 EDT 2010


Hello,

i am using CodeSynthesis XSD 3.2 (3.3). I need to read xml file, which
contains repeating sequence of elements. For example:

<?xml version="1.0" encoding="UTF-8"?>
<a xsi:noNamespaceSchemaLocation="example.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<text/>
	<value/>
	<text/>
	<value/>
	<value/>
</a>


If I am using a "xs:choice" to cover repeating elements (value and
text), than the sequence order is lost in C++ instance. 

I have tried to create an abstract layer between root element and
repeating elements to be able to use "xs:sequence" to keep an order of
elements in C++ like this

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
	<xs:element name="a">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="abs"
maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:complexType name="abs" abstract="true"/>
	<xs:element name="abs" type="abs" abstract="true"/>
	<xs:element name="text" type="text"/>
	<xs:complexType name="text">
		<xs:complexContent>
			<xs:extension base="abs"/>
		</xs:complexContent>
	</xs:complexType>
	<xs:element name="value" type="value"/>
	<xs:complexType name="value">
		<xs:complexContent>
			<xs:extension base="abs"/>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>

Unfortunately validation fails. Is this problem solvable?

Regards,
Alexey Glotov


More information about the xsd-users mailing list