Skip to content

System.Xml.Document : How to write special characters in an xml file ?

smashingraph

Asked Sep 28, 2005, 6:25 AM EDT1 answer
Share
LinkedInX
Hello, I have a little problem when saving my xml file. I use an instance of System.Xml.Document. I load an xml document file and edit this file with an application, then when I save it (doc.save("file.xml") ), I would like also the whitespaces being saved.

Example: 
<element>
  <subElement>            </subElement>
</element>

It saves correctly the whitespaces, but when I read it again, the whitespaces are trimmed! To prevent that, I would like to replace whitespaces by :  but on saving the xml writer encodes this sequence into :    and therefore it is not interpreted as a whitespace anymore... :(( Any help would be really appreciated, thanks in advance!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Have you properly set the "XmlDocument.PreserveWhitespace" Property of your XmlDocument instance?

    Also, Instead of using the decimal (base 10) entity, try using the (base 16) UniCode entity as in
    0