在Silverlight中的XML获取的所有节点名 [英] Get All node name in xml in silverlight

查看:89
本文介绍了在Silverlight中的XML获取的所有节点名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个这样的XML

i created one xml like this

<names>
<name>
nixon
</name>
</names>



我想迭代通过foreach循环或使用的XDocument Silverlight中的任何其他循环的每个节点名。

i want iterate each node name by foreach loop or any other loop in silverlight using xdocument.

我怎样才能得到这个节点的名字吗?

how can i get this node name?

推荐答案

您可以使用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.

这篇关于在Silverlight中的XML获取的所有节点名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆