delphi xpath xml query

前端 未结 4 493
温柔的废话
温柔的废话 2021-01-01 03:15

I\'m trying to locate the value for in the following XML File using a XPath query.



        
4条回答
  •  不知归路
    2021-01-01 04:02

    In the end I used OmniXML with the following code.

    uses
        OmniXML, OmniXMLUtils, OmniXMLXPath;
    
      ...
    
        function GetResultsURL(Filename: string): string;
        var
          FXMLDocument: IXMLDocument;
          XMLElementList: IXMLNodeList;
          XMLNode: IXMLNode;
          XMLElement: IXMLElement;
          i: integer;
        begin
          //Create and load the XML document
          FXMLDocument := CreateXMLDoc;
          FXMLDocument.Load(Filename);
    
          //We are looking for: 
          XMLElementList := FXMLDocument.GetElementsByTagName('Link');
          for i := 0 to Pred(XMLElementList.Length) do
            begin
              //Check each node and element
              XMLNode := XMLElementList.Item[i];
              XMLElement := XMLNode as IXMLElement;
              if XMLElement.GetAttribute('role') = 'output' then
                if Pos('failed', XMLNode.Text) > 0 then
                    Result := XMLNode.Text;
            end;
        end;
    

    The XML received looks like this ...

    ...
    
    
      12345
      https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/12345
      https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/12345/output/failed
      Completed
      2011-04-04T03:57:49.0534147-07:00
      2011-04-04T03:58:43.709725-07:00
      1
      1
      1
    
    
    ...
    

提交回复
热议问题