首先要初始化DOM
initialization
CoInitialize(nil);
finalization
CoUnInitialize;
1
uses msxml,msxmldom;
var
xdoc : IXMLDOMDocument;
xdn : IXMLDOMNode;
s : String;
begin
xdoc:=CreateDOMDocument();
xdoc.load('user.xml');
xdn:=xdoc.documentElement;
s:=xdn.selectSingleNode('/mail/config/folders/folder[@fid="2"]').attributes.getNamedItem('fname').nodeValue;
ShowMessage(s);
end;
2.
procedure TForm1.Button1Click(Sender: TObject);
var
SelectIntf:IDOMNodeSelect;
listIntf:IDOMNodeList;
pathstr:string;
begin
pathstr:='/Countries/Country'; //这儿就是XPATH查询串。
SelectIntf:=XMLDocument1.DOMDocument as IDOMNodeSelect;
listIntf:=SelectIntf.selectNodes(pathstr);
ShowMessage(intToStr( listIntf.length));
end;
3.
uses msxml;
var docNode:IXMLDOMNode;
begin
docNode:=(XMLDocument1.DocumentElement.DOMNode as IXMLDOMNodeRef).GetXMLDOMNode;
docNode.selectSingleNode('...........');
end;
本文介绍了使用Delphi进行DOM初始化及操作的方法,并演示了如何利用XPath进行节点选择和数据提取。通过实例展示了创建DOM文档、加载XML文件、选取特定节点属性及遍历节点列表的过程。
1777

被折叠的 条评论
为什么被折叠?



