Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XML serialization of a base class property

$
0
0

I need to serialize a class called "NodeCollection", which is a list of "Node" objects. "Node" is an abstract class from which I derive "NodeA" and "NodeB". I can successfully serialize the nodes in the collection. However, I am unable to serialize a public property in NodeCollection.

This is what I get:

 <NodeCollection>
   <ToolNode xsi:type="NodeA" Name="A" />
   <ToolNode xsi:type="NodeB" Name="B" />
 </NodeCollection>

and this is the desired output:

 <NodeCollection CollectionProperty="true">
   <ToolNode xsi:type="NodeA" Name="A" />
   <ToolNode xsi:type="NodeB" Name="B" />
 </NodeCollection>

The classes are defined as follows:

    [Serializable]
    [XmlRoot("NodeCollection")]
    [XmlInclude(typeof(NodeA))]
    [XmlInclude(typeof(NodeB))]
    public class NodeCollection : List<Node>
    {
        ...etc...
        [XmlElement("CollectionProperty")]
        public bool CollectionProperty
        {
            get { return m_CollectionProperty; }
            set { m_CollectionProperty = value; }
        }
        ...etc...

    }

    public abstract class Node
    {
        [XmlAttribute("Name")]
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }
    }

Do you know how I can get NodeCollection's public property "CollectionProperty" to show up in the serialization?

Thank you.


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>