Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Linq to XML - Projecting into poco's

$
0
0
Linq to XML - Projecting into poco's
.NET Development
Linq to XML - Projecting into poco's
Jul. 21, 2013
03:40 pm
3U50XKZK6Show this entire thread in new window
Gratar Image based on email address
From:Brett Baggott
To:All
I've got a Google Merchant Center rss feed that I'm trying to query and feed into a repository that will then be used as a basis for additional processing. I'm able to query the rss using Linq, traverse the result and then manually feed the repository, but my solution feels "hokey", and I'm sure there's a more direct way to query the XML and project directly into the repository.

Here's a link to an example of the rss feed:

http://www.nashvillewraps.com/rss/example-datafeed.xml

and here's an example of my best shot at a query that returns all the data as just a collection of elements:

XDocument doc = XDocument.Load(@"c:\small-datafeed.xml"); XNamespace ns = "http://base.google.com/ns/1.0"; var allElements = from elements in doc.Descendants("item").Descendants() select elements;foreach (var element in allElements) { Console.WriteLine(element.Name+": "+element.Value); Console.WriteLine(); }

If I remove ".Descendants()" from the query, of course I get a collection of "item" elements but those don't have child elements like I would expect (at least not that I can tell). I've not given an example of the Item class/model I'm trying to feed into because I don't think that's necessarily part of the problem. The problem is, how do I query the XML to return a collection of item(s) that contain a collection of elements.

I suspect there's something very basic here that I'm just not seeing.


Viewing all articles
Browse latest Browse all 10393

Trending Articles