zoukankan      html  css  js  c++  java
  • XPath and TXmlDocument

    XML example, from the OmniXML XPath demo:

    <?xml version="1.0" encoding="UTF-8"?>
    <bookstore>
      
    <book>
        
    <title lang="eng">Harry Potter</title>
      
    </book>
      
    <book>
        
    <title lang="eng">Learning XML</title>
      
    </book>
      
    <book>
        
    <title lang="slo">Z OmniXML v lepso prihodnost</title>
        
    <year>2006</year>
      
    </book>
      
    <book>
        
    <title>Kwe sona standwa sam</title>
      
    </book>
    </bookstore>

    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('.ooks.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;
  • 相关阅读:
    DWR3.0 如何应用的简单介绍(有实例)
    细线表格样式
    myeclipse不编译解决方法
    DORADO中resoler&dataProvider的常用方法
    jBPM插件下载地址及jBPM配置视频
    dorado要点总结
    千万级数据库(MSSQL)删除重复记录
    Dorado 7 IDE下载地址
    WIN CE和电脑之间的文件拷贝(2) Form1.cs文件
    获取所有存储过程源码替换存储过程方法
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/3179253.html
Copyright © 2011-2022 走看看