views:

62

answers:

1

I have the following xml file and I am trying to use linq to xml to get the Elements which are residing inside the CDATA section. Any suggestions please.

<?xml version = "1.0" encoding = "UTF-8"?>
<result final = "true" transaction-id="84WO" xmlns="http://cp.com/rules/client"&gt;
<client id = "CustName'>
<quoteback>
</client>
<report format = "CP XML">
<![CDATA[<?xml version="1.0" encoding = "UTF-8" standalone = "yes"?>
 <personal_auto xmlns = "http://cp.com/rules/client"&gt;
    <admin>
    </admin>
    <report>
    </report>
 </personal_auto>
]]>
</report> </result>
A: 

This is standard LINQ functionality - see http://msdn.microsoft.com/en-us/library/system.xml.linq.xcdata.aspx

Could you please explain the problem in more detail if this doesn't solve it?

Rushyo
My requirement is to get all the elements inside the CDATA section how can i get it using LINQ to XML
BumbleBee
Ah, you want someone to do your job for you. Not actually answer a question. Right. One quick Google later: http://www.jarvis.com.au/post/2008/09/I-love-Linq-to-XML.aspx
Rushyo
Rushyo. sorry. My XML file has an XML file inside CDATA section. The task that I am trying to achieve here is that I need to be able to navigate the xml file inside CDATA section and extract the necessary elements. any suggestions please?
BumbleBee
Right. So what you're saying is you have an XML document inside an XML document? All within a LINQ statement? Not sure that's possible, though I'd be happy for someone to correct me. Generally speaking, I can't imagine someone doing that.
Rushyo
I'd suggest just grabbing the CDATA element you want, loading the document, then executing a second query on it.
Rushyo
Thats right. How can I extract <personal_auto> which is inside CDATA section using LINQ to XML.
BumbleBee
I have come up with the following code var query = from element in xdoc.Root.DescendantNodesAndSelf() where element.NodeType == System.Xml.XmlNodeType.CDATA let textElement = element as XText select textElement.Value; foreach (var item in query) { XElement a = XElement.Parse(item); } Is there a better way to acheive the same? Thanks
BumbleBee