Overview
The XSD <sequence> and <all> entities define containers for other elements or element groups.
The items contained within a <sequence> must appear within the XML file in the order they are declared.
The items contained within an <all> can appear in any order within the XML file.
This sample demonstrates how this is dealt with in the generated code. |
|
Sample XSD
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="ParentSeq"> <xs:complexType>
<xs:sequence> <xs:element name="FirstChild" type="Xs:string"/>
<xs:element name="SecondChild" type="Xs:string"/> <xs:element name="ThirdChild" type="Xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

The Generated Code
The code generated for the sample XSD is shown here in its UML representation, note that there are 3 string properties (FirstChild, SecondChild & ThirdChild) corresponding with the child elements within ParentSeq.

Sample Code
The Code below shows how the resulting classes can be used create an XML document.
// create an instance of the class to load the XML file into
SequenceLib.ParentSeq elm = new SequenceLib.ParentSeq();
// Set data into element
elm.ThirdChild = "Some Data 3";
elm.FirstChild = "Some Data 1";
elm.SecondChild = "Some Data 2";
// Lets see what we've got
Trace.WriteLine(elm.ToXml());
The output from the sample above
<?xml version="1.0"?>
<!--Created by Liquid XML Data Binding Libraries (www.liquid-technologies.com) for simon-->
<ParentSeq xmlns:Xs="http://www.w3.org/2001/XMLSchema-instance">
<FirstChild>Some Data 1</FirstChild>
<SecondChild>Some Data 2</SecondChild>
<ThirdChild>Some Data 3</ThirdChild>
</ParentSeq>
Notes
It does not matter the order in which the child elements are set they will appear in the output XML correctly.
If the child elements are not in the correct order when an XML file is read in, then an exception is raised.
The element <all> works in the same way as <sequence>, the elements are written out in the order they where defined, but when they are read in they can be in any order.
|