views:

207

answers:

2

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?

+1  A: 

Lack of this behavior is unacceptable.

A standalone unescaped > is invalid XML.
XElement is designed to produce valid XML.

If you want to get the unescaped content of the element, use the Value property.

SLaks
Actually `>` is usually not required to be escaped. See http://www.w3.org/TR/REC-xml#syntax for the precise requirement. Nonetheless, I agree with being safe and escaping the `>` all the time. Any parser that conforms to the XML specification is required to understand `>`.
binarycoder
Is there any case in which the XElement could be induced to provide the raw string (including escaping, as in the file) rather than the unescaped `Value` content? Judging by what you are saying, it sounds like that it is the receiving code that has the problem.
Daniel I-S
Yes; `element.ToString()`.
SLaks
I'll check the existing code for this. Thanks.
Daniel I-S
A: 
binarycoder
I didn't use this, since you're right about the processing code being at fault - but this is the reply that most closely answers the question.
Daniel I-S