Vir
Vir

Reputation: 1354

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.

Upvotes: 2

Views: 1259

Answers (1)

Tim Jarvis
Tim Jarvis

Reputation: 18815

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

Upvotes: 1

Related Questions