博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
XPath and TXmlDocument
阅读量:7115 次
发布时间:2019-06-28

本文共 1700 字,大约阅读时间需要 5 分钟。

XML example, from the OmniXML XPath demo:

  
    
Harry Potter   
  
    
Learning XML   
  
    
Z OmniXML v lepso prihodnost     
2006
  
  
    
Kwe sona standwa sam   

Try something like this:

uses   XMLDoc, XMLDom, XMLIntf;  // From a post in Embarcadero's Delphi XML forum.  function selectNode(xnRoot: IXmlNode;const nodePath: WideString): IXmlNode;  var    intfSelect : IDomNodeSelect;    dnResult : IDomNode;    intfDocAccess : IXmlDocumentAccess;    doc: TXmlDocument;  begin    Result :=nil;    if not Assigned(xnRoot)or not Supports(xnRoot.DOMNode, IDomNodeSelect, intfSelect) then      Exit;    dnResult := intfSelect.selectNode(nodePath); if Assigned(dnResult) then begin if Supports(xnRoot.OwnerDocument, IXmlDocumentAccess, intfDocAccess) then        doc := intfDocAccess.DocumentObject      else        doc :=nil;       Result := TXmlNode.Create(dnResult,nil, doc);     end;  end; var  IDoc: IXMLDocument;  INode: IXMLNode; begin  IDoc := LoadXMLDocument('.\books.xml');  INode := SelectNode(IDoc.DocumentElement,'/bookstore/book[2]/title'); end; //================================================================================ procedure TForm1.Button1Click(Sender: TObject); var   noderef:IXMLDOMNodeRef;   root:IXMLDOMNode;   Node:IXMLDOMNode; begin   XMLDocument1.Active:=true;   noderef:=XMLDocument1.DocumentElement.DOMNode as IXMLDOMNodeRef;   root:=noderef.GetXMLDOMNode;   node:=root.selectSingleNode('node1/node2/node3/node4');   if Assigned(node) then   begin     ShowMessage(node.attributes.getnameditem('title').text);   end; end;

转载地址:http://flghl.baihongyu.com/

你可能感兴趣的文章
【AtCoder010】B - Boxes(差分)
查看>>
三种 Failover 之 Client-Side Connect time Failover、Client-Side TAF、Service-Side TAF
查看>>
ES 相似度算法设置(续)
查看>>
46:八进制到十进制
查看>>
JAVA4种线程池的使用
查看>>
MonkeyRunner 模块
查看>>
ASP.NET Core实现OAuth2.0的AuthorizationCode模式
查看>>
Atitit tomcat在linux服务器的启动与其他
查看>>
C++/Php/Python 语言执行shell命令
查看>>
Oracle表空间维护总结
查看>>
12C -- ORA-01017
查看>>
约瑟夫环问题
查看>>
Compile、Make和Build的区别(as make, build, clean, run)
查看>>
介绍三款串口监控工具:Device Monitoring Studio,portmon,Comspy
查看>>
Bulk Load-HBase数据导入最佳实践
查看>>
sqlServer的主键只能自增不能手动增加
查看>>
maven常用命令介绍
查看>>
【树莓派】树莓派上刷android系统
查看>>
J2EE之Servlet初见
查看>>
elasticsearch best_fields most_fields cross_fields从内在实现看区别——本质就是前两者是以field为中心,后者是词条为中心...
查看>>