C# System.Xml.Serialization Self-nested elements

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2010-05-17T17:56:42Z Indexed on 2010/05/17 18:10 UTC
Read the original article Hit count: 300

Filed under:
|

Hi, I am trying to deserialize

<graph>
<node>
   <node>
     <node></node>
   </node>
</node>
<node>
   <node>
     <node></node>
   </node>
</node>
</graph>

with

[XmlRoot("graph")]
class graph
{
   List<node> _children = new List<node>();

   [XmlElement("node")]
   public Node[] node
   {
      get { return _children.ToArray(); }
      set { foreach(node n in value) children.add(n) }
   };
}

class node
{
   List<node> _children = new List<node>();

   [XmlElement("node")]
   public Node[] node
   {
      get { return _children.ToArray(); }
      set { foreach(node n in value) children.add(n) }
   };
}

but it keeps saying object not created, null reference encountered when trying to set children nodes. What is wrong above?

Thanks in advance~

© Stack Overflow or respective owner

Related posts about c#

Related posts about xmlserializer