Posted on 2007-09-27 17:13
xyz 阅读(1659)
评论(0) 编辑 收藏 引用 所属分类:
DELPHI
直接设置XML内容:
xml1.XML.Text:='<option><sql>select * from abc</sql><count>2</count></option>';
xml1.Active:=true;
aNode := XML1.DocumentElement;
showmessage(aNode.NodeName);
逐节点加入:
var
XDoc :TXMLDocument;
Root :IXMLNode;
Node :IXMLNode;
begin
XDoc.Active := true;
Root := XDoc.AddChild('Root');
Node := Root.AddChild('Node');
Node.Attributes['Attrib'] := 'Attrib';
end;
读取XML节点:
var
XDoc :TXMLDocument;
sXML,sName,sAttr :AnsiString;
Root :IXMLNode;
Node :IXMLNode;
begin
XDoc.Active := false;
XDoc.XML.Text := sXML;
XDoc.Active := true;
Root = XDoc.DocumentElement;
if (Root.NodeName = 'Root')
begin
Node := Root.ChildNodes.Nodes[0];
//或者Node := Root.ChildNodes['sql'];
sName := Node.NodeName;
sAttr := Node.GetAttribute(A_Folder);
end
XDoc.Active := false;
end;