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;
[解决办法]
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(); }}