How not to encode values in XML
I have a xml document that I am editing in a C# script.
Here is the rub....
I am saving a SQL statement for the Salesforce inteface in the .value. When you use the .save it encodes (> into >) the string. I can't have this as Salesforce does know how to encode/decode so it has to be the specific string I set to. What is the best way to save the doc without encoding. I guess I could read the xml doc in and parse to a filestream editing the string when I get to it but it seems cumbersome....
An XML is - technically spoken - a string. In other words: a chain of characters.
What makes the difference are the mark-ups. You need special characters to distinguish them from the rest.
Three characters are absolutely sacrosanct: <, > and &
The first two build the mark-ups and the last one is the escape character, telling a reading instance: Look, this is a special character!
If you want to use these characters within XML you must escape them with <
>
and &
. The rest depends on the given encoding. UTF8 handles a different set of characters than UTF16 - and there are many more...
This means: There is no way around encoding/escaping such characters within XML.
If you want nothing more than to deal with the XML as string this is very easy: Your XmlDocument has OuterXML
, which is a string
returning property. It will deliver the whole XML as string.
But keep in mind, that your XML will break, if you use not encoded special characters in the wrong places...
EDIT
Actually there is a way around (as pointed out by Alexander Petrov: a CDATA section. The question is: How is the reciever reading your data? If everything goes the normal way, encodings are no problem as any reader will re-encode your data before showing it to the human reader.
链接地址: http://www.djcxy.com/p/29844.html下一篇: 如何不用XML编码值