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

  • SEARCH
  • Home
  • 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 1928626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T07:00:06+00:00 2026-05-17T07:00:06+00:00

I have a webbrowser and I use DocumentComplete to read the current document from

  • 0

I have a webbrowser and I use DocumentComplete to read the current document from the WebBrowser (as IHTMLDocument2).

What’s the easiest way to run xpath queries in that html doc? I am looking for something easy to use and lightweight.

I am using Visual Studio C++ 2010.

  • 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-05-17T07:00:07+00:00Added an answer on May 17, 2026 at 7:00 am

    What’s the easiest way to run xpath
    queries in that html doc? I am looking
    for something easy to use and
    lightweight.

    I am using Visual Studio C++ 2010.

    Generally, XPath expressions cannot be evaluated against HTML documents.

    However, if the HTML document is also an XHTML document (which is by definition a well-formed XML document), then XPath expressions can be evaluated against it.

    In particular using MS Visual C++, one can use code like this:

    #include <stdio.h>
    #import <msxml3.dll>
    using namespace MSXML2;
    
    void dump_com_error(_com_error &e);
    
    int main(int argc, char* argv[])
    {
      CoInitialize(NULL);
      try{
        IXMLDOMDocument2Ptr pXMLDoc = NULL;
        HRESULT hr = pXMLDoc.CreateInstance(__uuidof(DOMDocument30));
    
        // Set parser property settings
        pXMLDoc->async =  VARIANT_FALSE;
    
        // Load the sample XML file
        hr = pXMLDoc->load("hello.xsl");
    
        // If document does not load report the parse error 
        if(hr!=VARIANT_TRUE)
        {
          IXMLDOMParseErrorPtr  pError;
          pError = pXMLDoc->parseError;
          _bstr_t parseError =_bstr_t("At line ")+ _bstr_t(pError->Getline())
          + _bstr_t("\n")+ _bstr_t(pError->Getreason());
          MessageBox(NULL,parseError, "Parse Error",MB_OK);
          return 0;
        }
        // Otherwise, build node list using SelectNodes 
        // and returns its length as console output
        else
          pXMLDoc->setProperty("SelectionLanguage", "XPath");
          // Set the selection namespace URI if the nodes
          // you wish to select later use a namespace prefix
          pXMLDoc->setProperty("SelectionNamespaces",
          "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
          IXMLDOMElementPtr pXMLDocElement = NULL;
          pXMLDocElement = pXMLDoc->documentElement;
          IXMLDOMNodeListPtr pXMLDomNodeList = NULL;
          pXMLDomNodeList = pXMLDocElement->selectNodes("//xsl:template");
          int count = 0;
          count = pXMLDomNodeList->length;
          printf("The number of <xsl:template> nodes is %i.\n", count);
      }
      catch(_com_error &e)
      {
        dump_com_error(e);
      }
      return 0;
    }
    
    void dump_com_error(_com_error &e)
    {
      printf("Error\n");
      printf("\a\tCode = %08lx\n", e.Error());
      printf("\a\tCode meaning = %s", e.ErrorMessage());
      _bstr_t bstrSource(e.Source());
      _bstr_t bstrDescription(e.Description());
      printf("\a\tSource = %s\n", (LPCSTR) bstrSource);
      printf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
    }
    

    Read more about this code example here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webbrowser object on a winform that I would like to use
We have a windows application that contains an ActiveX WebBrowser control. As part of
I have an .Net Froms application that displays web pages through a WebBrowser control.
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
I use the WebBrowser component from WPF. I load there a page from Internet
I have a HTML page that I want to display in a WebBrowser control,
I have an object array that i'm returning to use the objects in a
I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser
I have been navigating the various WebBrowser control stackoverflow questions , and I can't
I have a WebBrowser Control and have called the Navigate(url) function of it for

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.