Reading XML with a Namespace via XElement

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im working on an application that includes an RSS reader, and came across something I dont know how to handle.<br/> <br/> The XML file is formed like so:<br/>
<pre lang=x-xml><?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 <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>[/code]
The problem I have is this:<br/> <br/> When I attempt to read the creator element with
<pre lang="x-c# NewItem.Creator = thisItem.Element("creator").Value;[/code]
I get an error, because thisItem.Element("creator") is null. How can I correctly resolve this element? Ive tried <br/>
<pre>NewItem.Creator = thisItem.Element("dc:creator").Value;[/code]
but that gives me an error saying that ":" is not a valid character in an element name. <br/> <br/> Im guessing Ill have to parse the namespace and prepend it to the element name, but how would I do that?<br/> <br/> Thanks!<br/> <br/> Gabe

View the full article
 
Back
Top