Hi there!
I have the following XSD (Well, this is not the real one, but the
concept is the same....)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:complexType name="DataItemType">
<xs:choice>
<xs:element name="Item1" type="Item1Type"/>
<xs:sequence>
<xs:element ref="Item2"/>
<xs:element ref="Item3"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:complexType name="Item1Type">
<xs:sequence>
<xs:element ref="Item1a"/>
<xs:element ref="Item1b"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Item1a" type="xs:string"/>
<xs:element name="Item1b" type="xs:string"/>
<xs:element name="Item2" type="xs:string"/>
<xs:element name="Item3" type="xs:string"/>
<xs:element name="MyData">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="DataItem"
type="DataItemType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
So far, so good. You see the xs:choice item, that consists of either the
complex type ItemType, or a sequence of Item2 and Item3 (both simple
strings).
So.. these are both valid xml files:
<MyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\mydata.xsd">
<DataItem>
<Item1>
<Item1a>Value1</Item1a>
<Item1b>Value2</Item1b>
</Item1>
</DataItem>
</MyData>
and...
<MyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\mydata.xsd">
<DataItem>
<Item2>Value1</Item2>
<Item3>Value2</Item3>
</DataItem>
</MyData>
Right. The XSD.Exe tool makes this of my XSD:
//----------------------------------------------------------------------
--------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.573
//
// Changes to this file may cause incorrect behavior and will be
lost if
// the code is regenerated.
// </autogenerated>
//----------------------------------------------------------------------
--------
//
// This source code was auto-generated by xsd, Version=1.1.4322.573.
//
using System.Xml.Serialization;
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="",
IsNullable=false)]
public class MyData {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Data Item")]
public DataItemType[] DataItem;
}
/// <remarks/>
public class DataItemType {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Item 2", typeof
(string))]
[System.Xml.Serialization.XmlElementAttribute("Item 3", typeof
(string))]
[System.Xml.Serialization.XmlElementAttribute("Item 1", typeof
(Item1Type))]
[System.Xml.Serialization.XmlChoiceIdentifierAttrib ute
("ItemElementName")]
public object Item;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName;
}
/// <remarks/>
public class Item1Type {
/// <remarks/>
public string Item1a;
/// <remarks/>
public string Item1b;
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(IncludeI nSchema=false)]
public enum ItemChoiceType {
/// <remarks/>
Item2,
/// <remarks/>
Item3,
/// <remarks/>
Item1,
}
Now, this doesn't seem right. I can now have in my XML file an Item1,
and Item2 OR an Item3, instead of an Item1 OR (an Item2 AND an Item3).
Can anybody help me out here? What is it that I am doing wrong?
Thanks in advance
Dennis Vroegop