BCB6下XML的操作, 使用TXMLDocument, 例子如下:
//--------------------------------------------------------------- XMLDocument-> FileName = Path; \\指定文件名
XMLDocument-> Active = true; \\激活XMLDocument, 载入文档内容
//取得XML文档节点个数
int NodeCount = XMLDocument-> DocumentElement-> ChildNodes-> Count;
//利用这种方法可以查找指定的XML节点 for (int i=0;i <NodeCount;i++) {
_di_IXMLNode Node = XMLDocument-> DocumentElement-> ChildNodes-> GetNode(i);
AnsiString NodeCaption = (AnsiString)Node-> ChildNodes-> Nodes[WideString( "Node1 ")]-> Text;
if (NodeCaption != ".... ") continue; ... ... }
//添加XML节点
_di_IXMLNode NewStock = XMLDocument-> DocumentElement-> AddChild(WideString( "Project "));
NewStock-> Attributes[WideString( "name ")] = Form_NewProject-> Edit_ProjectName-> Text;
_di_IXMLNode ValueNode = NewStock-> AddChild(WideString( "SourcePath "));
ValueNode-> Text = WideString(Form_NewProject-> Edit_SourcePath-> Text);
ValueNode = NewStock-> AddChild(WideString( "Include "));
ValueNode-> Text = WideString(Form_NewProject-> Edit_Include-> Text);
//读取指定的节点的属性值
int iYY = ((AnsiString)Node-> ChildNodes-> Nodes[WideString( "LastBackupDate ")]-> Attributes[WideString( "Year ")]).ToInt();
//直接修改节点值
Node-> ChildNodes-> Nodes[WideString( "Starting_Date ")]-> Attributes[WideString( "Year ")] = YY;
Node-> ChildNodes-> Nodes[WideString( "Starting_Date
")]-> Attributes[WideString( "Month ")] = MM;
Node-> ChildNodes-> Nodes[WideString( "Starting_Date ")]-> Attributes[WideString( "Day ")] = DD;
Node-> ChildNodes-> Nodes[WideString( "Starting_Date ")]-> Text = WideString(Form_Properties-> DatePicker-> Date.DateString());
//删除节点
XMLDocument-> DocumentElement-> ChildNodes-> Delete(i);
//保存XML文件
XMLDocument-> SaveToFile(Path);