开发者

XML CDATA Encoding

开发者 https://www.devze.com 2023-03-14 10:38 出处:网络
I know to use CreateCDataSection to generate a CDATA node. However, is there any way to insert a CDATA string into my original string? Instead of having the whole node being enclosed by CDATA tag. Bel

I know to use CreateCDataSection to generate a CDATA node. However, is there any way to insert a CDATA string into my original string? Instead of having the whole node being enclosed by CDATA tag. Below is my code. Please advise, thanks.

var detail = new StringBuilder();
detail.AppendFormat("<![CDATA[<br />]]>another line: {0}", foo1);
detail.AppendFormat("<![CDATA[<br />]]>another line: {0}", foo2);
detail.AppendFormat("<![CDATA[<br />]]>another line: {0}", foo开发者_开发技巧3);

var xmlOutput = new XElement("Detail",detail);


Instead of CDATA, use &lt; for the '<'.

detail.AppendFormat("&lt;br />another line: {0}", foo1);
detail.AppendFormat("&lt;br />another line: {0}", foo2);
detail.AppendFormat("&lt;br />another line: {0}", foo3);

var xmlOutput = new XElement("Detail", detail);


are you looking for this.

        var br = new XCData("<br />");
        detail.AppendFormat("{0}another line: {1}", br, foo1);
        detail.AppendFormat("{0}another line: {1}", br, foo2);
        detail.AppendFormat("{0}another line: {1}", br, foo3);            
        var xmlOutput = new XElement("Detail", detail);
0

精彩评论

暂无评论...
验证码 换一张
取 消