I’m populating an XElement with information and writing it to an xml file using the XElement.Save(path) method. At some point, certain characters in the resulting file are being escaped – for example, > becomes >.
This behaviour is unacceptable, since I need to store information in the XML that includes the > character as part of a password. How can I write the ‘raw’ content of my XElement object to XML without having these escaped?
The XML specification usually allows
>to appear unescaped.XDocumentplays it safe and escapes it although it appears in places where the escaping is not strictly required.You can do a replace on the generated XML. Be aware per http://www.w3.org/TR/REC-xml#syntax, if this results in any
]]>sequences, the XML will not conform to the XML specification. Moreover,XDocument.Parsewill actually reject such XML with the error “‘]]>’ is not allowed in character data.”.In consideration that any spec-compliant XML parser must support
>, I’d highly recommend fixing the code that is processing the XML output of your program.