XDocument获取所有具有属性的节点
我有以下 XML 文档:
<parameters>
<source value="mysource" />
<name value="myname" />
<id value="myid" />
</parameters>
我正在尝试使用 XDocument 解析此 XML,以便获得包含节点及其值的列表(字典):
source => mysource, name => myname, id => myid
关于如何执行此操作的任何想法?
I have the following XML document:
<parameters>
<source value="mysource" />
<name value="myname" />
<id value="myid" />
</parameters>
I'm trying to parse this XML, using XDocument so that I would get a list (Dictionary) containing the node and it's value:
source => mysource, name => myname, id => myid
Any ideas on how I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我在 LINQPad 中尝试了这一点,它提供了您正在寻找的内容:
I tried this out in LINQPad and it provides what you are looking for:
如果您有一个包含此处显示内容的文档,则应该可以:
Provided you have a document with the content you show here, this should work:
您可以使用 xmldocument/ xmtextreader 对象使用这些链接,这些链接将有所帮助
http://msdn.microsoft.com/en-us/library/c445ae5y(v=vs.80).aspx
http://www.c-sharpcorner.com/uploadfile/mahesh/readwritexmltutmellli2111282005041517am/readwritexmltutmellli21.aspx
但我强烈建议如果可能的话使用linq 到 xml非常容易且易于管理
http://www.codeproject.com/KB/linq/LINQtoXML.aspx
You can use xmldocument/ xmtextreader object use these links these will help
http://msdn.microsoft.com/en-us/library/c445ae5y(v=vs.80).aspx
http://www.c-sharpcorner.com/uploadfile/mahesh/readwritexmltutmellli2111282005041517am/readwritexmltutmellli21.aspx
but i strongly suggest if possible use linq to xml that is far easy and manageable
http://www.codeproject.com/KB/linq/LINQtoXML.aspx
像这样的东西
希望这有帮助
Something like this
Hope this helps