creating cdata in xml
><![CDATA[BEGIN:VCARD
VERSION:3.0
FN:D Formatted Name
N:D Surname;D Given name;D Additional names;D Name prefix;D Name Suffix
ORG:D Organization Unit;D Org Unit
END:VCARD
]]>
how do i write this in a xml file i have to 开发者_JAVA技巧replace all 'D' with user entered value.
IMO if you are using .NET then when you are writing XML use the Linq to XML classes (XElement, XDocument etc) they provide a DOM free way of writing code.
Then writing a CData section is trivial....
var result = new XElement("MyElemName",
new XCData("BEGIN:VCARD......etc")
);
Note when reading from a CData section in Linq to XML, you don't need to do anything special, just use the (string) typecast overload on the Element and it will handle the CData section for you....
var cdataBit = (string)x.Element("MyElemName");
精彩评论