使用XDocument获取特定属性的值 [英] Get value of specific attribute using XDocument

查看:50
本文介绍了使用XDocument获取特定属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有以下XML文件:

<?xml version="1.0" encoding="utf-8"?>
<Parent>
  <Attr1>1</Attr1>
  <Child>
    <GrandSon>
       <Attr1>1</Attr1>
    </GrandSon>
  </Child>
</Parent>


我想得到"Attr1"的值在"父母"之下然后是"Attr1"的值。在"GrandSon"下。 

I want to get the value of "Attr1" under "Parent" and then the value of "Attr1" under "GrandSon". 

你能提供一个简单的例子吗?

Can you please provide a simple example ?

XDocument doc = XDocument.Load("d:/Temp/My.xml");
...

谢谢,

Zvika 

Zvika 

推荐答案

看看
XElement.Attribute
 在MSDN上,它提供了一个示例。

Have a look at XElement.Attribute on MSDN, it provides a sample.

要从XDocument检索XElement,请参阅
XDocument
 

To retrieve XElement from XDocument refer to XDocument on MSDN


这篇关于使用XDocument获取特定属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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