📜  c# loop xml - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:55.691000             🧑  作者: Mango

代码示例1
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.
       //
        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;
        }
    }
}