csharp loop xml

Code Example - csharp loop xml

                
                        XmlReader reader = XmlReader.Create(new System.IO.StringReader(settings));
while (reader.Read())
{
    // Note! This does loop all the ways through your xml (even child nodes)
    if (reader.NodeType == XmlNodeType.Element)
    {
		// additionally you can see switch between the nodes.
       //<parent test="asd"><child /></parent>
		switch (reader.LocalName)
        {
          case "parent":
			// Here you can access the attributes
            for (int i = 0; i < reader.AttributeCount; i++)
            {
                reader.MoveToAttribute(i);   // i = 1
                string name = reader.Name; 	 // test
				string value = reader.Value; // asd
            }
            break;

          case "child":
            break;
        }
    }
}