更新时间:2023-11-24 20:18:10
您可以使用DescendantsAndSelf的XElement的()方法来获取所有节点和他们的名字。
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()返回元素的集合包含此元素,而这种元素的所有后代元素,文档顺序。
DescendantsAndSelf() Returns a collection of elements that contain this element, and all descendant elements of this element, in document order.