首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

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

2012-03-31 
NativeXML 在C++ Builder中的用法NativeXML 自带的例子,如何翻译成C++ Builder?procedure CreateXMLvarAD

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();   }} 

热点排行