Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:54:18+00:00 2026-06-15T06:54:18+00:00

Are there any library’s for Delphi that would allow parsing HTML with XPath or

  • 0

Are there any library’s for Delphi that would allow parsing HTML with XPath or XQuery. Similar to what PHP has built in by default. For example FLWOR..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:54:19+00:00Added an answer on June 15, 2026 at 6:54 am

    I don’t know of any libraries, but here is my XE2 helper class unit with the SelectNode(s) function that I use to ‘do’ XPath. The RemoveNameSpaces and XMLToTree functions do not apply, but who knows when they might come in handy 😉

    unit uXMLHelper;
    
    interface
    
    Uses
       System.SysUtils, System.Classes, System.TypInfo, Vcl.ComCtrls,
       XML.XMLDoc, XMLDom, XML.XMLIntf;
    
    type
       TXMLHelper = class
       public
          class function SelectNode(StartNode: IXmlNode; const NodeXPath: WideString): IXmlNode;
          class function SelectNodes(StartNode: IXmlNode; const NodeXPath: WideString): IXMLNodeList;
          class function RemoveNameSpaces(XMLString: String): String;
          class procedure XMLToTree(XmlDoc: IXMLDocument; TV: TTreeView);
       end;
    
    function ConcatNodeNames(NodeNames: Array of String): String;
    // Concatenates the strings in NodeNames to /name1/name2/.../namex
    
    implementation
    
    Uses
       MSXML2_TLB; // IXMLDOMdocument
    
    class function TXMLHelper.RemoveNameSpaces(XMLString: String): String;
    const
      // An XSLT script for removing the namespaces from any document. It will remove the prefix as well.
      // From http://wiki.tei-c.org/index.php/Remove-Namespaces.xsl
      cRemoveNSTransform =
        '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
        '<xsl:output method="xml" indent="no"/>' +
    
        '<xsl:template match="/|comment()|processing-instruction()">' +
        '    <xsl:copy>' +
        '      <xsl:apply-templates/>' +
        '    </xsl:copy>' +
        '</xsl:template>' +
    
        '<xsl:template match="*">' +
        '    <xsl:element name="{local-name()}">' +
        '      <xsl:apply-templates select="@*|node()"/>' +
        '    </xsl:element>' +
        '</xsl:template>' +
    
        '<xsl:template match="@*">' +
        '    <xsl:attribute name="{local-name()}">' +
        '      <xsl:value-of select="."/>' +
        '    </xsl:attribute>' +
        '</xsl:template>' +
    
        '</xsl:stylesheet>';
    
    var
      Doc, XSL: IXMLDOMdocument2;
      Res     : string;
      p       : Integer;
    begin
      Doc := ComsDOMDocument.Create;
      Doc.ASync := false;
      XSL := ComsDOMDocument.Create;
      XSL.ASync := false;
      try
         Doc.loadXML(XMLString);
         XSL.loadXML(cRemoveNSTransform);
         Res := Doc.TransFormNode(XSL);
         // This now contains the original text with a <?xml version="1.0" encoding="UTF-16"?> prepended; remove it:
         p := Pos('?>',Res);
         result := Copy(Res,P+2);
      except
         on E:Exception do Result := E.Message;
      end;
    end; { RemoveNameSpaces }
    
    
    class function TXMLHelper.SelectNode(StartNode: IXmlNode; const NodeXPath: WideString): IXmlNode;
    // Geeft de node in path NodeXPath onder StartNode
    // http://delphi.about.com/od/delphi-tips-2011/qt/select-single-node-ixmlnode-txmlnode-xpath-delphi-xmldom.htm
    var
      intfSelect    : IDomNodeSelect;
      dnResult      : IDomNode;
      intfDocAccess : IXmlDocumentAccess;
      XMLDoc        : TXmlDocument;
    begin
      Result := nil;
      if not Assigned(StartNode)
        or not Supports(StartNode.DOMNode, IDomNodeSelect, intfSelect) then
        Exit;
    
      dnResult := intfSelect.selectNode(NodeXPath);
      if Assigned(dnResult) then
      begin
        if Supports(StartNode.OwnerDocument, IXmlDocumentAccess, intfDocAccess) then
          XMLDoc := intfDocAccess.DocumentObject
        else
          XMLDoc := nil;
        Result := TXmlNode.Create(dnResult, nil, XMLDoc);
      end;
    end; { SelectNode }
    
    
    class function TXMLHelper.SelectNodes(StartNode: IXmlNode; const NodeXPath: WideString): IXMLNodeList;
    (* Returns a list of all nodes in path NodeXPath below StartNode.
     * NodeXPath is relative; e.g. with:
     *
     * <Envelope>                            <= DocumentElement root
     *    <Body>
     *       <FindItemResponse>
     *          <ResponseMessages>
     *             <FindItemResponseMessage>
     *                <RootFolder>           <= IRootNode
     *                   <Items>
     *                      <CalendarItem>
     *
     * these are identical:
     *   SelectNodes(DocumentElement,'Envelope/Body/FindItemResponse/ResponseMessages/FindItemResponseMessage/RootFolder/Items/CalendarItem')
     *   SelectNodes(DocumentElement,'/Envelope/Body/FindItemResponse/ResponseMessages/FindItemResponseMessage/RootFolder/Items/CalendarItem')
     *   SelectNodes(IRootNode,'Items/CalendarItem')
     *
     * http://delphi.about.com/od/vclusing/qt/delphi-select-xml-nodes-ixmlnodelist-selectnodes-xpath-xmldom.htm
     *)
    var
      intfSelect    : IDomNodeSelect;
      intfAccess    : IXmlNodeAccess;
      dnlResult     : IDomNodeList;
      intfDocAccess : IXmlDocumentAccess;
      XMLDoc        : TXmlDocument;
      i             : Integer;
      dn            : IDomNode;
    begin
      Result := nil;
      if not Assigned(StartNode)
        or not Supports(StartNode, IXmlNodeAccess, intfAccess)
        or not Supports(StartNode.DOMNode, IDomNodeSelect, intfSelect) then
        Exit;
    
      dnlResult := intfSelect.selectNodes(NodeXPath);
      if Assigned(dnlResult) then
      begin
        // Since the XPath implementation of SelectNodes returns an IDomNodeList and we need an IXMLNodeList
        // we need to "wrap" a call to IDomNodeSelect.selectNodes into a function that will result in IXMLNodeList.
        Result := TXmlNodeList.Create(intfAccess.GetNodeObject, '', nil);
        if Supports(StartNode.OwnerDocument, IXmlDocumentAccess, intfDocAccess) then
          XMLDoc := intfDocAccess.DocumentObject
        else
          XMLDoc := nil;
    
        for i := 0 to dnlResult.length - 1 do
        begin
          dn := dnlResult.item[i];
          Result.Add(TXmlNode.Create(dn, nil, XMLDoc));
        end;
      end;
    end; { SelectNodes }
    
    
    procedure DomToTree(XmlNode: IXMLNode; TV: TTreeView; TreeNode: TTreeNode);
    var
       I: Integer;
       NewTreeNode: TTreeNode;
       NodeText: string;
       AttrNode: IXMLNode;
    begin
      // Skip text nodes and other special cases
      if XmlNode.NodeType <> ntElement then Exit;
      try
         // Add the node itself
         NodeText := XmlNode.NodeName;
         if XmlNode.IsTextElement then
           NodeText := NodeText + ' = ' + XmlNode.NodeValue;
         NewTreeNode := TV.Items.AddChild(TreeNode, NodeText);
         // Add attributes
         for I := 0 to xmlNode.AttributeNodes.Count - 1 do
         begin
           AttrNode := xmlNode.AttributeNodes.Nodes[I];
           TV.Items.AddChild(NewTreeNode,
             '[' + AttrNode.NodeName + ' = "' + AttrNode.Text + '"]');
         end;
         // add each child node
         if XmlNode.HasChildNodes then
           for I := 0 to xmlNode.ChildNodes.Count - 1 do
             DomToTree (xmlNode.ChildNodes.Nodes [I], TV, NewTreeNode);
      except
         on E:Exception do
            TV.Items.AddChild(TreeNode, E.Message);
      end;
    end; { DomToTree }
    
    
    class procedure TXMLHelper.XMLToTree(XmlDoc: IXMLDocument; TV: TTreeView);
    begin
       XMlDoc.Active := true;
       TV.Items.Clear;
       DomToTree(XMLDoc.DocumentElement,TV,nil);
    end; { XMLToTree }
    
    
    function ConcatNodeNames(NodeNames: Array of String): String;
    var Res,Nam : String;
    begin
       for Nam in NodeNames do Res := Res + '/' + Nam;
       Result := Res;
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any Javascript library that could force an HTML node (mostly images and
Is there any library similar to PostGIS for PHP-Mysql? I'm dealing with hundreds of
Is there any library available (or well-written algorithm reference I could implement) that would
Is there any library out there in .NET that creates standard-compliant html (understood by
Is there any library that supports exporting html and SVG to PDF?
Is there any Library for .NET that returns SPARQL results in some structured List
Is there any library out there that I can use to create epub files
Is there any library to use Comet in Rails 3? I read that Juggernaut
Is there any library that will help me to get date for easter sunday
Is there any library out there for C, C++, or .NET that implements a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.