I was trying to serialize xml, the sample structure like this
<nodes>
<node1>87576</node1>
<node2>10</node2>
<crsa>
<crsa x="0">3487</crsa>
<crsa x="1">0</crsa>
<crsa x="2">0</crsa>
</crsa>
<node3>0</node3>
<node4>131</node4>
</nodes>
This is the generated class.
[XmlRoot(ElementName = "nodes")]
public class Nodes
{
[XmlElement(ElementName = "node1")]
public string node1 { get; set; }
[XmlElement(ElementName = "node2")]
public string node2 { get; set; }
[XmlElement(ElementName = "node3")]
public string node3 { get; set; }
[XmlElement(ElementName = "crsa")]
public Crsa[] crsa { get; set; }
[XmlElement(ElementName = "node4")]
public string node4 { get; set; }
}
[XmlRoot(ElementName = "crsa")]
public class Crsa
{
[XmlAttribute("x")]
public string X { get; set; }
[XmlText]
public string Text { get; set; }
}
When I serialize the xml to the class, the crsa array values are getting empty. The other node values are serialized correctly.
When I generated the class using http://xmltocsharp.azurewebsites.net/ the Crsa is not an array public Crsa crsa { get; set; }. I tried with both but the values are getting empty.
crsaelement has been given two completely different roles to play, being both the container and the contained item.