xml字符串里的特殊字符如何转义为xml格式

一、xml字符串里的特殊字符如何转义为xml格式

string xml="<itemRule><field id=\"prop_13021751\" name=\"货号\" type=\"input\"><rules><rule name=\"requiredRule\"";

xml=System.Web.HttpUtility.HtmlDecode(xml);
//结果
xml:
<?xml version="1.0" encoding="utf-8" ?><itemRule><field id="prop_13021751" name="货号" type="input"><rules><rule name="requiredRule"

二、xml格式字符串特殊字符格式化

string xml=";

xml=System.Security.SecurityElement.Escape(xml);
//结果
xml:
<?xml version=\"1.0\" encoding=\"utf-8\" ?>&lt;itemRule&gt;&lt;field id=\"prop_13021751\" name=\"货号\" type=\"input\"&gt;&lt;rules&gt;&lt;rule name=\"requiredRule\"

你可能感兴趣的:(C#,类库,方法)