XML serialization: choice

E

eSapient

I generated serialization/deserialization code for this schema using
the xsd tool:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="FAAAvxType">
<xs:sequence>
<xs:choice>
<xs:sequence>
<xs:element name="geoLat" type="xs:string"/>
<xs:element name="geoLong" type="xs:string"/>
<xs:element name="valGeoAccuracy" type="xs:double" minOccurs="0"/>
<xs:element name="uomGeoAccuracy" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:element name="SpnGroupAvx" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:element name="FAAAvx" type="FAAAvxType"/>
</xs:schema>

The following code was generated (edited for brevity):

using System.Xml.Serialization;

[System.Xml.Serialization.XmlRootAttribute("FAAAvx", Namespace="",
IsNullable=false)]
public class FAAAvxType {

[System.Xml.Serialization.XmlElementAttribute("valGeoAccuracy",
typeof(System.Double))]
[System.Xml.Serialization.XmlElementAttribute("geoLong",
typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("uomGeoAccuracy",
typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("SpnGroupAvx",
typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("geoLat",
typeof(string))]

[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public object Item;

[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName;
}

[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]
public enum ItemChoiceType
{
valGeoAccuracy,
geoLong,
uomGeoAccuracy,
SpnGroupAvx,
geoLat,
}


My question is: what should be the code to serialize an 'FAAAvx'
instance which contains both, a 'geoLat' as well as a 'geoLong'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top