Linq to XML,如何在C#中访问元素? [英] Linq to XML, how to acess an element in C#?
本文介绍了Linq to XML,如何在C#中访问元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我需要解析的XML:
Here is my XML I need to parse:
<root>
<photo>/filesphoto.jpg</photo>
<photo:mtime>12</photo:mtime>
<text>some text</text>
</root>
要访问<text>
元素,请使用以下代码:
To access the <text>
element I use this code:
var doc = XDocument.Parse(xml.Text);
doc.Descendants("text").FirstOrDefault().Value;
如何访问<photo:mtime>
?
推荐答案
这是xml的非法格式,我的朋友 你不能有一个冒号
it is an illegal format of xml my friend you cannot have a colon
这篇关于Linq to XML,如何在C#中访问元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文