1
我有一个XML文档:Windows 7移动的Silverlight:LINQ到XML问题
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>blahblah</title>
<subtitle>blahblah.</subtitle>
<link href="blahblah"/>
<link href="blahblah"/>
<updated>blahblah</updated>
<author>
<name>blahblah</name>
</author>
<id>blahblah</id>
<entry>
<title>blahblah</title>
<content type="html"><![CDATA[“some text.”]]></content>
</entry>
</feed>
我想要得到的入口节点的内容信息,这里是我的代码:
var xmlTreeVal = XDocument.Load("myxml.xml");
var returnVal = from item in xmlTreeVerse.Descendants("feed").Elements("entry")
select new VerseModel
{
Verse = item.Element("content").Value
};
XML文档加载罚款(正如我可以告诉通过调试),但它一直抛出'没有顺序项目发现'的错误。如何找到“内容”节点信息?
谢谢!是否有一个特定的原因,你必须使用它?我已经读过,你应该使用它来避免命名冲突,但我不知道你必须使用它。 – contactmatt 2010-11-14 04:40:32
@contactmatt如果在XML中指定了它,则必须使用它。您可以使用'Where'子句作为解决方法,如[本问题](http://stackoverflow.com/q/1145659)中所示,但它不如直接引用名称空间那样高效。如果您的XML没有名称空间,那么您可以直接通过名称查询节点。 – 2010-11-14 04:53:48