读书人

NativeXML 在C++ Builder中的用法解决

发布时间: 2012-03-31 13:13:26 作者: rapoo

NativeXML 在C++ Builder中的用法
NativeXML 自带的例子,如何翻译成C++ Builder?

procedure CreateXML;
var
ADoc: TNativeXml;
begin
// Create new document with a rootnode called "Root"
ADoc := TNativeXml.CreateName('Root');
try
// Add a subnode with name "Customer"
with ADoc.Root.NodeNew('Customer') do begin
// Add an attribute to this subnode
WriteAttributeInteger('ID', 123456);
// Add subsubnode
WriteString('Name', 'John Doe');
end;

// Save the XML in readable format (so with indents)
ADoc.XmlFormat := xfReadable;
// Save results to a file
ADoc.SaveToFile('c:\test.xml');
finally
ADoc.Free;
end;
end;



[解决办法]

C/C++ code
void __fastcall TForm1::FormCreate(TObject *Sender){   TNativeXml *ADoc;   TXmlNode *node;   ADoc = new TNativeXml("Root");   try   {      node = ADoc->Root->NodeNew("Customer");      node->WriteAttributeInteger("ID", 123456);      node->WriteString("Name", "John Doe");      ADoc->XmlFormat = xfReadable;      ADoc->SaveToFile("c:\\test.xml");   }   __finally   {      ADoc->Free();   }} 

读书人网 >C++ Builder

热点推荐