How to Parse an XML (using XELement) having multiple Namespace ?

Posted by Subhen on Stack Overflow See other posts from Stack Overflow or by Subhen
Published on 2010-03-22T10:05:02Z Indexed on 2010/03/22 10:21 UTC
Read the original article Hit count: 273

Filed under:
|
|
|
|

Hi I , I get the followinng Xresponse after parsing the XML document:

 <DIDL-Lite 
xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" 
       xmlns:dc="http://purl.org/dc/elements/1.1/" 
       xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" 
       xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/">
<item id="1182" parentID="40" restricted="1"> 
<title>Hot Issue</title> 
</item> 

As per the earlier thread, When there is a default namespace in the document, you must parse it as if it were a named namespace. For example.

XNamespace ns = "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"; 

var xDIDL = xResponse.Element(ns + "DIDL-Lite"); 

But in my case I have four different name space. I am not getting any results after using the following query , I am getting the response , Not Yeilding any results:

   XNamespace dc = "http://purl.org/dc/elements/1.1/";
     var vAudioData = from xAudioinfo in xResponse.Descendants(ns + "DIDL-lite").Elements("item")
                                                                                             select new RMSMedia
                                                     {
         strAudioTitle = ((string)xAudioinfo.Element(dc + "title")).Trim(),
};

I have no clue whats going on as am new to it. Please help

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight