Is there any C# function which could be used to escape and un-escape a string, which could be used to fill in the content of an XML element?

And how to unescape?

 

【解决方案】

public static string XmlEscape(string unescaped)

{

XmlDocument doc = new XmlDocument();

XmlNode node = doc.CreateElement("root");

node.InnerText = unescaped;

return node.InnerXml;

}

 

public static string XmlUnescape(string escaped)

{

XmlDocument doc = new XmlDocument();

XmlNode node = doc.CreateElement("root");

node.InnerXml = escaped;

return node.InnerText;

}

posted on 2017-02-21 11:26  今夜太冷  阅读(474)  评论(0编辑  收藏  举报