I'm trying to read some specific nodes i the following XML document and I'm having difficulties reding the Field nodes. I would like to read and capture all the nodes and child nodes between the <errors> node to be able to store in database
<ServerErrors>
<Error>
<CODE>AABB</CODE>
<POSITION>52</POSITION>
<MESSAGE>message1</MESSAGE>
<KeyFields>
<Field>
<NAME>ModeID</NAME>
<VALUE>44</VALUE>
</Field>
<Field>
<NAME>TypeID</NAME>
<VALUE>11</VALUE>
</Field>
<Field>
<NAME>otherType</NAME>
<VALUE>22</VALUE>
</Field>
<Field>
<NAME>RunDate</NAME>
<VALUE>2007/07/10</VALUE>
</Field>
<Field>
<NAME>ClassCode</NAME>
<VALUE>TT</VALUE>
</Field>
</KeyFields>
</Error>
<Error>
<CODE>AABB</CODE>
<POSITION>52</POSITION>
<MESSAGE>
message1
</MESSAGE>
<KeyFields>
<Field>
<NAME>ModeID</NAME>
<VALUE>42</VALUE>
</Field>
<Field>
<NAME>TypeID</NAME>
<VALUE>12</VALUE>
</Field>
<Field>
<NAME>otherType</NAME>
<VALUE>21</VALUE>
</Field>
<Field>
<NAME>RunDate</NAME>
<VALUE>2007/07/10</VALUE>
</Field>
<Field>
<NAME>ClassCode</NAME>
<VALUE>TF</VALUE>
</Field>
</KeyFields>
</Error>
<ServerErrors>
XmlNodeList errorNodes = doc.GetElementsByTagName("Error");
foreach (XmlNode errorNode in errorNodes)
{
foreach (XmlNode childNode in errorNode.ChildNodes)
{
Code = errorNode["CODE"].InnerText;
Position = errorNode["POSITION"].InnerText;
Message = errorNode["MESSAGE"].InnerText;
// if (childNode.Name.Equals("KeyFields"))
// {
// XmlNodeList fieldNodes = doc.GetElementsByTagName("Field");
// foreach (XmlNode fieldNode in fieldNodes)
// {
// foreach (XmlNode fnode in fieldNode.ChildNodes)
// {
// cName = fieldNode["NAME"].InnerText;
// cValue = fieldNode["VALUE"].InnerText;
// }
// }
// }
}
}