XML : Parsing complex XML, no descendent elements exists when selecting a named element

I'm having an issue parsing a complex XML file. I can't get the descendants by name. I'm trying to simply grab the feed->entry->content->m:properties->d:title elements, but I can't even grab the first descendants by name. Please help.

   string XML = @"<feed xmlns:base=""https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch"" xmlns:d=""http://schemas.microsoft.com/ado/2007/08/dataservices"" xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" xmlns=""http://www.w3.org/2005/Atom""><title type=""text"">sushi</title><subtitle type=""text"">Bing Related Search</subtitle><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'</id><rights type=""text"" /><updated>2015-11-23T22:33:13Z</updated><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=0&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">c6b512cc-e93a-48f4-9691-e61dc0c184df</d:ID><d:Title m:type=""Edm.String"">Sushi Near My Current Location</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Sushi+Near+My+Current+Location</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=1&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">49fb106e-d74c-440b-a4f7-8942f357fcf7</d:ID><d:Title m:type=""Edm.String"">Types of Sushi</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Types+of+Sushi</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=2&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">086097d2-243a-4376-9580-eee5ac721ec7</d:ID><d:Title m:type=""Edm.String"">Types of Sushi Rolls</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Types+of+Sushi+Rolls</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=3&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">0fa4548f-fda9-4d0a-88fc-e8952846e1d6</d:ID><d:Title m:type=""Edm.String"">Sushi Guide</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Sushi+Guide</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=4&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">a9a6bc5a-363d-48bf-87c1-f4dd71f9a18c</d:ID><d:Title m:type=""Edm.String"">Sushi Recipes for Beginners</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Sushi+Recipes+for+Beginners</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=5&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">d00b0830-8148-43cf-b3db-b7f9623e3428</d:ID><d:Title m:type=""Edm.String"">Sushi Places Near Me</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Sushi+Places+Near+Me</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=6&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">28a56f1f-a03a-4337-8576-3681fd38ec9b</d:ID><d:Title m:type=""Edm.String"">How to Make Sushi</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=How+to+Make+Sushi</d:BingUrl></m:properties></content></entry><entry><id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/RelatedSearch?Query='sushi'&amp;$skip=7&amp;$top=1</id><title type=""text"">RelatedSearchResult</title><updated>2015-11-23T22:33:13Z</updated><content type=""application/xml""><m:properties><d:ID m:type=""Edm.Guid"">e961500c-1068-4740-950a-0fdf48fe005f</d:ID><d:Title m:type=""Edm.String"">Sushi Rolls Pictures and Names</d:Title><d:BingUrl m:type=""Edm.String"">http://www.bing.com/search?q=Sushi+Rolls+Pictures+and+Names</d:BingUrl></m:properties></content></entry></feed>";            XElement root = XElement.Parse(XML);            //Has descendants, including entry items.          var capabilities1 = root.Descendants();            //No Results for any of these.           var capabilities2 = root.Descendants("entry");          var capabilities3 = root.Elements("entry");          var capabilities4 = root.Descendants().Where(c => c.Name == "entry");    

No comments:

Post a Comment