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 298641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:45:01+00:00 2026-05-12T06:45:01+00:00

I have a bit of XML as follows: <section> <description> <![CDATA[ This is a

  • 0

I have a bit of XML as follows:

<section>
  <description>
    <![CDATA[
      This is a "description"
      that I have formatted
    ]]>
  </description>
</section>

I’m accessing it using curXmlNode.SelectSingleNode("description").InnerText but the value returns

\r\n      This is a "description"\r\n      that I have formatted

instead of

This is a "description" that I have formatted.

Is there a simple way to get that sort of output from a CDATA section? Leaving the actual CDATA tag out seems to have it return the same way.

  • 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-12T06:45:01+00:00Added an answer on May 12, 2026 at 6:45 am

    You can use Linq to read CDATA.

    XDocument xdoc = XDocument.Load("YourXml.xml");
    xDoc.DescendantNodes().OfType<XCData>().Count();
    

    It’s very easy to get the Value this way.

    Here’s a good overview on MSDN: http://msdn.microsoft.com/en-us/library/bb308960.aspx

    for .NET 2.0, you probably just have to pass it through Regex:

         string xml = @"<section>
                          <description>
                            <![CDATA[
                              This is a ""description""
                              that I have formatted
                            ]]>
                          </description>
                        </section>";
    
            XPathDocument xDoc = new XPathDocument(new StringReader(xml.Trim()));
            XPathNavigator nav = xDoc.CreateNavigator();
            XPathNavigator descriptionNode = 
                nav.SelectSingleNode("/section/description");
    
            string desiredValue = 
                Regex.Replace(descriptionNode.Value
                                         .Replace(Environment.NewLine, String.Empty)
                                         .Trim(),
                    @"\s+", " ");
    

    that trims your node value, replaces newlines with empty, and replaces 1+ whitespaces with one space. I don’t think there’s any other way to do it, considering the CDATA is returning significant whitespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of code that basically reads an XML document using the
I have a bit of Xml that looks something like this: <books> <book id=1>
I have to read/write an XML file that stores its data as bit masked
Could someone please explain to me a bit about this XML schema. I have
My XPath is a little bit rusty... Let's say I have this simple XML
I have an .asmx webservice that returns some XML. A sample bit of XML
I have this bit of XML <status complete=false> <messages> <message>Message 1</message> <message>Message 2</message> <message>Message
I have a bit of xml file named Sample.xml which is shown below <?xml
Bit of a beginner question here: Say I have a block of xml: <root>
Right, bit of a strange question; I have been doing some linq to XML

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.