Get All node name in xml in silverlight

后端 未结 2 951
梦谈多话
梦谈多话 2021-01-17 06:57

i created one xml like this



nixon


i want iterate each node name by foreach loop or

相关标签:
2条回答
  • 2021-01-17 07:30

    You can use the DescendantsAndSelf() method of XElement to get all the nodes and their names.

    foreach (XElement child in doc.Root.DescendantsAndSelf())
    {
        Console.WriteLine(child.Name.LocalName);
    }
    

    DescendantsAndSelf() Returns a collection of elements that contain this element, and all descendant elements of this element, in document order.

    0 讨论(0)
  • 2021-01-17 07:33

    With LinqToXml:

    var xDoc = XDocument.Parse(mySmlString);
    var names = xDoc.Root.Elements("name").Select(x=> x.Value.Trim()).ToArray();
    foreach (var name in names)
    {
        System.Console.WriteLine(name);
    }
    
    0 讨论(0)
提交回复
热议问题