//生成xml文件
_di_IXMLDocument XML = NewXMLDocument();
XML->Active=true;
XML->Options<<doNodeAutoIndent;
XML->Encoding = "GB2312";
XML->StandAlone="yes";
XML->AddChild("EXCERA");
_di_IXMLNode ROOT = XML->DocumentElement;
ROOT->Attributes["Version"]="R3.03";
ROOT->Attributes["Path"]="NamePath";
_di_IXMLNode cNode = ROOT->AddChild("DeviceInfo");
cNode->Attributes["DeviceName"]="VP350";
cNode->Attributes["FrequencyRange"]="350-400MHZ";
cNode = ROOT->AddChild("Comunication");
cNode->Attributes["TYPE"]="USB";
cNode->Attributes["Port"]="1";
XML->SaveToFile("d:\\PDT自动化测试系统.xml");
//读取节点数据
AnsiString GetNodeData(_di_IXMLNode pNode,AnsiString nodeName,AnsiString defaultValue)
{
_di_IXMLNodeList nodeLst = pNode->ChildNodes;
_di_IXMLNode node = nodeLst->FindNode(nodeName);
if(NULL==node) return defaultValue;
return node->GetText();
}
//写入节点数据
void UpdateNodeData(_di_IXMLNode pNode,AnsiString nodeName,AnsiString nodeValue)
{
_di_IXMLNodeList nodeLst = pNode->ChildNodes;
_di_IXMLNode node = nodeLst->FindNode(nodeName);
if(NULL==node)
{
node->AddChild(nodeName);
}
else node->SetText(nodeValue);
}
XMLDoc->LoadFromFile("d:\\mytip.xml");
XMLDoc->Active=true;
_di_IXMLNode Root = XMLDoc->DocumentElement;
_di_IXMLNodeList NodeList = Root->ChildNodes;
_di_IXMLNode Node = NodeList->FindNode("Message");
NodeList = Node->ChildNodes;
AnsiString Temp = GetNodeData(Node,"Time","other");
UpdateNodeData(Node,"Time","2013-8");
XMLDoc->SaveToFile("d:\\mytip.xml");