简体   繁体   中英

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 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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM