I have an XML element that looks something like this:
<content locale="en"> </content>
The text between the bracketed stuff consists of a single space character. When I load the XML into an XmlDocument look at the XmlElement object for the above element, I expect:
contentElement.InnerText.Length == 1; // InnerText should be a single space character
but instead what I get is
contentElement.InnerText.Length == 0;
Assuming this is not a bug in Microsoft’s DOM implementation, is this a feature of the XML/DOM specification I’m not aware of? If so, do I have any options but to add escaped whitespace characters when the XML is written out?
If you want to have whitespace preserved inside of your XML file after being parsed please consider using
<![CDATA[and]]>section to let parser know that it should take this character data literally…