I have an xml file with child nodes that I want to read. When I deserialize the object I won't get the value from the child nodes, its always 0.
Xmlfile example:
<?xml version="1.0" encoding="utf-8"?>
<Pieces Rapport="0" Employee="">
<Piece Roll="1" Piece="1" Amount="1" Length="1.00" />
<Piece Roll="1" Piece="1" Amount="1" Length="2.00" />
<Piece Roll="1" Piece="1" Amount="1" Length="3.00" />
<Piece Roll="1" Piece="1" Amount="1" Length="0" />
<Piece Roll="1" Piece="1" Amount="1" Length="0" />
</Pieces>
I marked my classes with the [XmlElement]
tag as stated here: How to deserialize xml to object
classes:
[XmlRoot("Pieces")]
public class StukLijst
{
[XmlElement("Rapport")]
public string rapport { get; set; }
[XmlElement("Employee")]
public string employee { get; set; }
[XmlElement("Piece")]
public List<StukRow> stukLijst { get; set; }
}
public class StukRow
{
[XmlElement("Roll")]
public int rol { get; set; }
[XmlElement("Piece")]
public int stuk { get; set; }
[XmlElement("Amount")]
public int banen { get; set; }
[XmlElement("Length")]
public double lengte { get; set; }
}
read the xml file:
private void LoadXml(string pickListNumber, string lineNumber)
{
string path = filePath + pickListNumber + "_" + lineNumber + ".xml";
StreamReader xmlStream = new StreamReader(path);
XmlSerializer serializer = new XmlSerializer(typeof(StukLijst));
StukLijst result = (StukLijst)serializer.Deserialize(xmlStream);
}
and the result is the following:
So why is Employee null
while the childnodes are all 0
?
It seems like it can find the childs but doesn't get the data from them.
Any solutions?