Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Reading XML with a Namespace via XElement

$
0
0
I'm working on an application that includes an RSS reader, and came across something I don't know how to handle.

The XML file is formed like so:
<?xml version="1.0" encoding="windows-1251"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Feed Title</title><link>http://feed.net/</link><language>en</language><description>A really cool feed</description><generator>DataLife Engine</generator><item><title>Item Title</title><guid isPermaLink="true">http://feed.net/item.html</guid><link>http://feed.net/item.html</link><description><![CDATA[<div align="center">a bunch of HTML in here</div><br /><br />]]></description><category><![CDATA[Category Name]]></category><dc:creator>Creator Name</dc:creator><pubDate>Tue, 02 Mar 2010 17:34:33 +0300</pubDate></item></channel></rss>
The problem I have is this:

When I attempt to read the creator element with
NewItem.Creator = thisItem.Element("creator").Value;
I get an error, because thisItem.Element("creator") is null.  How can I correctly resolve this element?  I've tried
NewItem.Creator = thisItem.Element("dc:creator").Value;
but that gives me an error saying that ":" is not a valid character in an element name. 

I'm guessing I'll have to parse the namespace and prepend it to the element name, but how would I do that?

Thanks!

Gabe

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>