Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3469
  • Last Modified:

XML: creating IXMLNode with CData type

Hi all,
I've trouble in using TXMLDocument to create an XML file
such as below mentioned:
<header>
  <body>
   <![CDATA[This is my data]]>
  </body>
</header>,

For a note, I've use this kind of code
var
  bdy: IXMLNode;
begin
 Xmldocument.version:= '1.0';
 Xmldocument.encoding:= 'utf-8';
 Xmldocument.addchild('header');
 bdy:= xmldocument.documentelement.addchild('body');
 bdy.nodevalue:= 'This is my data';
end;

Someone can help me?

Thanks
Sirro
0
sirro
Asked:
sirro
1 Solution
 
shaneholmesCommented:
var
 hdr, bdy, dat: IXMLNode;
begin
 XMLDocument1.Active:= True;
 Xmldocument1.version:= '1.0';
 Xmldocument1.encoding:= 'utf-8';
 hdr:= Xmldocument1.addchild('header');
 bdy:= xmlDocument1.CreateNode('body', ntElement);
 hdr.ChildNodes.Add(bdy);
 dat:= xmlDocument1.CreateNode('This is my data', ntCDATA);
 bdy.ChildNodes.Add(dat);
 Memo1.Lines.Assign(XMLDocument1.XML);
end;
0
 
BlackTigerXCommented:
procedure TForm1.Button1Click(Sender: TObject);
var
  bdy: IXMLNode;
begin
Xmldocument1.Active:=True;
 Xmldocument1.version:= '1.0';
 Xmldocument1.encoding:= 'utf-8';
 Xmldocument1.addchild('header');
 bdy:= xmldocument1.documentelement.addchild('body');
 bdy.nodevalue:= '<![CDATA[This is my data]]>';

 Xmldocument1.SaveToFile('f:\test.xml');

end;
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now