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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:34:56+00:00 2026-06-18T16:34:56+00:00

A surprisingly simple question this time! :-) There’s an XML file like this: <xml>

  • 0

A surprisingly simple question this time! 🙂 There’s an XML file like this:

<xml>
  <data> </data>
</xml>

Now I need to read exactly whatever is in the <data> element. Be it a single whitespace like U+0020. My naive guess:

XmlDocument xd = new XmlDocument();
xd.Load(fileName);
XmlNode xn = xd.DocumentElement.SelectSingleNode("data");
string data = xn.InnerText;

But that returns an empty string. The white space got lost. Any other data can be read just fine.

What do I need to do to get my space character here?

After browsing the web for a while, I tried reading the XML file with an XmlReader that lets me set XmlReaderSettings.IgnoreWhitespace = false but that didn’t help.

  • 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-06-18T16:34:58+00:00Added an answer on June 18, 2026 at 4:34 pm

    You must use xml:space="preserve" in your XML, according to the W3C standards and the MSDN docs.

    The W3C standards dictate that white space be handled differently
    depending on where in the document it occurs, and depending on the
    setting of the xml:space attribute. If the characters occur within the
    mixed element content or inside the scope of the xml:space=”preserve”,
    they must be preserved and passed without modification to the
    application. Any other white space does not need to be preserved. The
    XmlTextReader only preserves white space that occurs within an
    xml:space=”preserve” context.

            XmlDocument xd = new XmlDocument();
            xd.LoadXml(@"<xml xml:space=""preserve""><data> </data></xml>");
            XmlNode xn = xd.DocumentElement.SelectSingleNode("data");
            string data = xn.InnerText; // data == " "
            Console.WriteLine(data == " "); //True
    

    Tested HERE.

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

Sidebar

Related Questions

This is a simple SystemVerilog question that I am having a surprisingly difficult time
I've checked through other questions and surprisingly this question doesn't seem to have been
Very simple question (surprisingly I can't find a similar question anywhere): how do I
I'm sure it's a simple problem. I read from serial port some data and
I have probably a simple math problem that I'm having surprisingly hard time figuring
So I'm making this android application, that needs to read data from user-provided CSV
I'm talking about this surprisingly simple implementation of rand() from the C standard: static
It must be simple, but surprisingly I couldn't find an answer to this problem
I'm surprisingly frustrated by this, and I suspect the answer is simple. I have
Surprisingly simple/stupid/basic question, but I have no idea: Suppose I want to return the

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.