-
XML Schema question
Let's say I have an XML document in the following format:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Document>
<Object>
<Child1>
<SomeData></SomeData>
</Child1>
<Child2>
<SomeData></SomeData>
</Child2>
<Child3>
<SomeData></SomeData>
</Child3>
</Object>
<Object>
<Child1>
<SomeData></SomeData>
</Child1>
</Object>
</Document>
The XML schema for this file looks like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Document">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Object">
<xs:complexType>
<xs:sequence>
<xs:element name="Child1">
<xs:complexType>
<xs:sequence>
<xs:element name="SomeData" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="Child2">
<xs:complexType>
<xs:sequence>
<xs:element name="SomeData" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="Child3">
<xs:complexType>
<xs:sequence>
<xs:element name="SomeData" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
is there a way to modify the XML schema file to recognize the individual <Child*> elements, but treat them as an array of <Child> elements (minOccurs="1" maxOccurs="unbounded") in code (C#) generated from the schema?
-
Doesn't xsd do this for you? If I remember correctly if your schema is correct xsd will create arrays for you. However there is a bug in xsd that causes multiple definitions to occur.
-
the problem is with the fact that the elements are Child1, Child2, Child3, etc. xsd just sees them as independent elements, and doesn't know to put them into an array.