2009-11-02 7 views
1

다음 XML에서 레코드를 얻을 수 있습니다.Linq 네임 스페이스 문제

의 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 

답변

2

귀하의 코드는 나를 위해 잘 작동 작동 제거하는 경우 :

using System; 
using System.Collections.Generic; 
using System.Xml.Linq; 
using System.Linq; 

class Test  
{  
    static void Main() 
    { 
     XNamespace nsAtom = "http://www.w3.org/2005/Atom"; 
     var feed = XElement.Load("test.xml"); 
     Console.WriteLine(feed.Descendants(nsAtom + "entry").Count()); 
    } 
} 

(아무 것도하지 않았기 때문에 쿼리 식을 제거했지만 그 전에도 작동했습니다.)

test.xml은 질문에 표시된 XML로 설정됩니다.

오류 코드로 feed을 인쇄하면 어떻게됩니까?