Parse Simple XML C#

string s @="<?xml version=""1.0"" encoding=""utf-8"" ?><Parent><Plate>ABC123</Plate></Parent>";
XmlDocument x = new XmlDocument();
x.LoadXml(s);
XmlNode rootnode = x["Parent"];

if ((rootnode != null) && (rootnode.HasChildNodes))
{
     XmlNodeList nodes = rootnode.ChildNodes;

     for (int i = 0; i < nodes.Count; i++)
     {
         XmlNode node = nodes[i];
         Console.WriteLine("Name: " + node.Name + " " + node.InnerText);
     }
}

Leave a Reply