Linq命名空间问题
我似乎可以从以下 xml 中获取任何记录。
xmlns="http://www.w3.org/2005/Atom"
如果我删除上面的内容就可以了
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<entry><id><![CDATA[text]]></id><
author><name><![CDATA[film24]]></name></author><title><![CDATA[text]]></title>
<updated>2009-10-30T15:55:13+00:00</updated><published>2009-10-30T00:00:00+00:00</published>
<media:thumbnail type="image/jpeg" title="thumbnail" url=""/>
<media:content type="video/flv" title="video" url="" expression="high"/>
<media:content type="video/flv" title="video" url="" expression="low"/>
</entry>
</feed>
//My linq
XNamespace nsAtom = "http://www.w3.org/2005/Atom";
string url = HttpContext.Current.Server.MapPath(ConfigHelper.GetValue("FeedUri"));
var feed = XElement.Load(url);
var query = from c in feed.Descendants(nsAtom + "entry")
select c;
return query.Count(); // always returns o
I can seem to get any records from the following xml.
xmlns="http://www.w3.org/2005/Atom"
If i remove the above it works
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<entry><id><![CDATA[text]]></id><
author><name><![CDATA[film24]]></name></author><title><![CDATA[text]]></title>
<updated>2009-10-30T15:55:13+00:00</updated><published>2009-10-30T00:00:00+00:00</published>
<media:thumbnail type="image/jpeg" title="thumbnail" url=""/>
<media:content type="video/flv" title="video" url="" expression="high"/>
<media:content type="video/flv" title="video" url="" expression="low"/>
</entry>
</feed>
//My linq
XNamespace nsAtom = "http://www.w3.org/2005/Atom";
string url = HttpContext.Current.Server.MapPath(ConfigHelper.GetValue("FeedUri"));
var feed = XElement.Load(url);
var query = from c in feed.Descendants(nsAtom + "entry")
select c;
return query.Count(); // always returns o
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码对我来说工作得很好:(
我删除了查询表达式,因为它没有做任何事情,但它在那之前也工作过。)
这只是将
test.xml
设置为你的 XML已在问题中显示。如果您打印出包含失败代码的
feed
,您会看到什么?Your code works fine for me:
(I've removed the query expression because it wasn't doing anything, but it worked before then too.)
That's just with
test.xml
set to the XML you've shown in the question.If you print out
feed
with your failing code, what do you see?