delphi中xml之xpath查询总结

首先要初始化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;

 

你可能感兴趣的:(xml,Delphi)