views:

273

answers:

1

Hi currently I have a nested XMl , having the following Structure :

<?xml version="1.0" encoding="utf-8" ?> 
<Response>
    <Result>
        <item id="something" />
        <price na="something" />
        <?xml version="1.0" encoding="UTF-8" ?>
        <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/">
    </Result>
    <NumberReturned>10</NumberReturned>
    <TotalMatches>10</TotalMatches>
</Response> 

Any help on how to read this using Xdocument or XMLReader will be really helpfull.

Thanks, Subhendu

+1  A: 

XDocument and XmlReader are both XML parsers that expect a properly formed XML as input. What you have shown is not a XML file. So the first task would be to extract the nested XML and as this is not valid XML you cannot rely on any parser to do this job. You'll need to resort to string manipulation and or regular expressions.

My suggestion would be to fix the procedure generating this invalid XML in the first place. Another suggestion is to never generate a XML file manually but use an appropriate tool for this (XmlWriter, XDocument, ...)

Darin Dimitrov