I have a string in the database which contains angle brackets (less-than/greater-than). I need to insert the string into an XElement and then serialise it to a client device. Now the html entities obviously get encoded so the brackets appear as < and > and the best way may be is to use the HttpUtility.HtmlDecode to decode the entities back on the client device. But I am wondering is there anyway to escape the encoding and have these entities send as is?
That still turns it into < and > (doesn't not keep it as < and >)
Shahid
2010-07-23 12:07:48
You need to handled this on client. With < and > xml will be malformed.
Orsol
2010-07-23 12:46:09
A:
If you set the XElement.Value property, yes, it will be encoded when it's serialized. But when you deserialize it on the client and access the XElement.Value property, it will be unencoded. See this quick sample:
var htmlData = "<some data>";
XElement element = new XElement("data");
element.Value = htmlData;
var xml = element.ToString();
var data = element.Value;
if (data != htmlData)
throw new NotImplementedException("this didn't work");
If you set a breakpoint, you'll see the variable 'xml' does contain the encoded html string.
Patrick Steele
2010-07-23 12:22:00