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;
}
}
}
string xml = @"
<parent>
<child>
<nested />
</child>
<child>
<other>
</other>
</child>
</parent>
";
XmlReader rdr = XmlReader.Create(new System.IO.StringReader(xml));
while (rdr.Read())
{
if (rdr.NodeType == XmlNodeType.Element)
{
Console.WriteLine(rdr.LocalName);
}
}