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

Re: Linq to XML - Projecting into poco's

$
0
0
Re: Linq to XML - Projecting into poco's
.NET Development
Re: Linq to XML - Projecting into poco's
Jul. 22, 2013
05:16 am
3U60BAZLKShow this entire thread in new window
Gratar Image based on email address
From:Rick Strahl
To:Brett Baggott

When you query a selection of elements you get node objects and if those node objects have children those should show up in the child collections. I can't look this up this moment so I don't know the exact syntax but there should be a ChildNodes collection or something to that effect on each of the <item> elements that you can iterate through individually.

The XLINQ result is just nested collections...

+++ Rick ---


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.




Rick Strahl
West Wind Technologies


from Geneva


Viewing all articles
Browse latest Browse all 10393

Trending Articles