Sample code for 30+ languages & platforms
Delphi DLL

Using CDATA in XML

See more XML Examples

Demonstrates how to force the content of a node to be encapsulated in CDATA.

The output of the following program is an XML document that looks like this:


<root>
    <year>2009</year>
    <junk1>abc .. &lt; &amp; &gt; 123</junk1>
    <junk2><![CDATA[abc .. < & > 123]]></junk2>
</root>

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Xml;

...

procedure TForm1.Button1Click(Sender: TObject);
var
xml: HCkXml;
child1: HCkXml;
child2: HCkXml;
child3: HCkXml;

begin
xml := CkXml_Create();

CkXml_putTag(xml,'root');

child1 := CkXml_NewChild(xml,'year','2009');

child2 := CkXml_NewChild(xml,'junk1','abc .. < & > 123');

child3 := CkXml_NewChild(xml,'junk2','abc .. < & > 123');
CkXml_putCdata(child3,True);

CkXml_Dispose(child1);
CkXml_Dispose(child2);
CkXml_Dispose(child3);

Memo1.Lines.Add(CkXml__getXml(xml));

CkXml_Dispose(xml);

end;