Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:07:14+00:00 2026-05-25T22:07:14+00:00

I have searched around looking for ways to get at the CDATA section text

  • 0

I have searched around looking for ways to get at the CDATA section text area and found very luk warm solutions using linq. I need to extract the XML imbedded in the CDATA Section so I can pull out different pieces of info. I have the following XML:

<Envelope>
 <Warehouse />
 <Payload>
  - <![CDATA[ 
    <?xml version="1.0"?>
    <ROOT>
      <ORDERID>399798</ORDERID>
      <PRODUCTNUMBER>00003997</PRODUCTNUMBER>
      <DESCIPTION>Red Rider BB-Gun</DESCIPTION>
      <STATUS>InStock</STATUS>
      <LOCATION>Chicago</LOCATION>
    </ROOT> ]]>
 </Payload>
</Envelope>

So I would like if possible to do this by extracting the whole cdata section into an XDocument so I can use Linq to query. Also if I just wanted to pull out a single Element from the CData section. How can I do this? Using Linq?

I have tried using this Linq code below to give me back cdata section but can’t do anything with it since it comes back as an IEnumerable. I’m probably missing something easy so I come to you the Linq wizards for some help.

Here’s the code I mentioned:

 var queryCDATAXML = from el in xdoc.DescendantNodes()
                     where el.NodeType == XmlNodeType.CDATA
                     select el.Parent.Value.Trim();

Is there a way to do a select new XDocument or XmlDocument like so:

//This doesn't compile.
 var queryCDATAXML = from el in xdoc.DescendantNodes()
                            where el.NodeType == XmlNodeType.CDATA
                            select new XDocument()
                              {  
                                 el.Parent.Value.Trim();
                              }   

If I am going about this all wrong or their is a better way to accomplish this I’m open for suggestions. 🙂

Thanks,
DND

Code Update:

var queryCDATAXML = from el in xdoc.DescendantNodes()
                     where el.NodeType == XmlNodeType.CDATA
                     select el.Parent.Value.Trim();

var xdoc = XDocument.Parse(queryCDATAXML);

Generates this error:
Argument ‘1’: cannot convert from ‘System.Collections.Generic.IEnumerable’ to ‘string’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:07:15+00:00Added an answer on May 25, 2026 at 10:07 pm

    Rather than new XDocument, try XDocument.Parse

    var queryCDATAXML = // get the value
    var xdoc = XDocument.Parse(queryCDATAXML);
    

    You’re getting some Enumerable<string> rather than string, so you need to just get the single value.

    var node = xdoc.DescendantNodes().Single(el => el.NodeType == XmlNodeType.CDATA);
    var content = node.Parent.Value.Trim();
    var xdoc = XDocument.Parse(content);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched around a bit, and have not really found a professional type
I have searched around the internet and stack and have not quite found the
I've searched around but haven't quite found what I'm looking for. In a nutshell
I have searched around and found some tutorials for xsl:key and key() function, but
I've done a lot of looking around and have not found what I'm looking
I have searched around but I am not very experienced with PHP. The script
I've been looking around the internet and haven't found out how, but have found
I have searched around, and it seems that this is a limitation in MS
I have searched/Googled around but I'm struggling with the following problem. I am building
I have searched far and wide on the Internet but have not found anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.