 |
 |
 |
This may be a simple question, but I'm struggling to find the answer
to it, so any suggestions would be greatly appreciated.... I want to
know if there's some way to ensure that the xsi:type attribute is
included when serializing a c# class.
The basic situation is this:
I have a class, ClassB which derives from ClassA.
ClassC contains a list of ClassB, which I want to serialize as an
XmlArray of 'bListItem's as per the code below:
[Serializable]
[XmlType("classA")]
public class ClassA
{
private string _id;
[XmlAttribute("id")]
public string Id
{
get { return _id; }
set { _id = value; }
}
}
[Serializable]
[XmlType("classA.classB")]
public class ClassB : ClassA
{
private string _name;
[XmlAttribute("name")]
public string Name
{
get { return _name; }
set { _name = value; }
}
}
[Serializable]
[XmlType("classC")]
public class ClassC
{
private string _id;
private List<ClassB> _bList;
[XmlAttribute("id")]
public string Id
{
get { return _id; }
set { _id = value; }
}
[XmlArray("bList"), XmlArrayItem("bListItem")]
public List<ClassB> BList
{
get { return _bList; }
set { _bList = value; }
}
}
Now... this serializes to the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<classC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="C1">
<bList>
<bListItem id="B1" name="My B Item" />
</bList>
</classC>
What I want to do is have the xsi:type of bListItem come through in
this element like so:
<?xml version="1.0" encoding="utf-8" ?>
<classC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="C1">
<bList>
<bListItem xsi:type="classA.classB" id="B1" name="My B Item" /
>
</bList>
</classC>
Can anyone tell me how to do this?
Thanks in advance...
Bonnie
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |