开发者

XML CDATA Encoding

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜