c# - Xdocument and linq - doesn't cycle thru the elements -


given xml request (with xxx replaced whatever user wanted), cant figure out why it's not returning 2 test objects list should.

string youtubexml = new webclient().downloadstring("http://gdata.youtube.com/feeds/api/users/xxxxxxxxx/uploads?orderby=published"); xdocument xdoc = xdocument.parse(youtubexml);  list<dynamic> videos = (from in xdoc.descendants("entry")                         select new                         {                             //just declaring random                             title = i.element("id").value                          }).tolist<dynamic>(); 

and xml structure looks this:

<feed xmlns="http://www.w3.org/2005/atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <id>http://gdata.youtube.com/feeds/api/users/xxxxxxxx/uploads</id> <author>   <name>xxxxxxxx</name>   <uri>http://gdata.youtube.com/feeds/api/users/xxxxxxxx</uri> </author> <generator version="2.1" uri="http://gdata.youtube.com">youtube data api</generator> <opensearch:totalresults>5</opensearch:totalresults> <opensearch:startindex>1</opensearch:startindex> <opensearch:itemsperpage>25</opensearch:itemsperpage> <entry>   <id>http://gdata.youtube.com/feeds/api/videos/video1</id>   <published>date</published>   <updated>date</updated>   <author>     <name>name</name>     <uri>http://gdata.youtube.com/feeds/api/users/xxxxxxx</uri>   </author>   <yt:hd />   <media:group>     <yt:duration seconds="179" />   </media:group>   <gd:rating average="4.703704" max="5" min="1" numraters="81" rel="http://schemas.google.com/g/2005#overall" />   <yt:statistics favoritecount="0" viewcount="6004" /> </entry> <entry>   <id>http://gdata.youtube.com/feeds/api/videos/video2</id>   <published>date</published>   <updated>date</updated>   <author>     <name>name</name> <uri>http://gdata.youtube.com/feeds/api/users/xxxxxxx</uri>   </author>   <yt:hd />   <media:group>     <yt:duration seconds="179" />   </media:group>   <gd:rating average="4.703704" max="5" min="1" numraters="81"         rel="http://schemas.google.com/g/2005#overall" />   <yt:statistics favoritecount="0" viewcount="6004" /> </entry> </feed> 

what possible going wrong? xml being received , parsed, it's query not working.

you're missing fact, xml uses namespaces, query has use namespaces too:

var ns = xnamespace.get("http://www.w3.org/2005/atom"); var videos = (from in xdoc.root.elements(ns + "entry")               select new               {                   title = (string)i.element(ns + "id")               }).tolist(); 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -