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 <
for the '<'.
detail.AppendFormat("<br />another line: {0}", foo1);
detail.AppendFormat("<br />another line: {0}", foo2);
detail.AppendFormat("<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);
精彩评论