BCB6下XML的操作,使用TXMLDocument,例子如下: //---------------------------------------------------------------XMLDocument->FileName=Path;指定文件名 XMLDocument->Active=true;激活XMLDocument,载入文档内容 //取得XML文档节点个数 intNodeCount=XMLDocument->DocumentElement->ChildNodes->Count; //利用这种方法可以查找指定的XML节点for(inti=0;i<NodeCount;i++){ _di_IXMLNodeNode=XMLDocument->DocumentElement->ChildNodes->GetNode(i); AnsiStringNodeCaption=(AnsiString)Node->ChildNodes->Nodes[WideString("Node1")]->Text; if(NodeCaption!="....")continue;......} //添加XML节点 _di_IXMLNodeNewStock=XMLDocument->DocumentElement->AddChild(WideString("Project")); NewStock->Attributes[WideString("name")]=Form_NewProject->Edit_ProjectName->Text; _di_IXMLNodeValueNode=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); //读取指定的节点的属性值 intiYY=((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); (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|