BCB6下XML的操作

前端之家收集整理的这篇文章主要介绍了BCB6下XML的操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

猜你在找的XML相关文章