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 8062761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:46:50+00:00 2026-06-05T10:46:50+00:00

I am working on a XPATH generator (using absolute paths). The idea is that

  • 0

I am working on a XPATH generator (using absolute paths).
The idea is that I have a function where you pass a HTMLElement (that is found in the webbrowser) and it will return the XPATH like:

/html/body/div[3]/div[1]/a

The function to generate the xpath looks something like this:

HTMLElement node=...;
while (node != null)
     {
       int i = FindElementIndex(node); //find the index of our current node in the parent elements
       if(i==1)
          xpath.Insert(0, "/" + node.TagName.ToLower());
       else
          xpath.Insert(0, "/" + node.TagName.ToLower() + "[" + i+ "]");
       node = node.Parent;
    }

The idea is this:

a)take the element

b)find the index position of element in element.parent

c)append xpath

The problem appears when the parent is a custom html code like “<layer>”
Example:

<html>
  <body>
     <div>
        <layer>
           <a href="http://site.com">aaa</a>
        </layer>
      </div>
  </body>
</html>

If our HTMLElement is <a href="http://site.com">aaa</a> and we call
ourelement.Parent it will return the DIV element and NOT the element

So instead of having:
/html/body/div/layer/a

We will have (which is incorrect)
/html/body/div/a

How can this be solved? Really hope someone can help figure this out.

EDIT 1: Just for testing purposes I implemented the function from Get the full path of a node, after get it with an XPath query in JavaScript

The results were that if the page that contained a “custom” tag (like <layer>) AND if the page was opened in firefox, the xpath was showed correctly.

If the page was opened in Internet Explorer (like webbrowser is) the <layer> was not included as a parent.

So the issue is with internet explorer not “parsing” the dom correctly. What is the solution? What function can help create xpath for cases like this (if using webbrowser htmlelement).

  • 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-05T10:46:52+00:00Added an answer on June 5, 2026 at 10:46 am

    This is not a direct answer to your question; but have considered using http://htmlagilitypack.codeplex.com/ to load the HTML. It will not have the problem of ignoring the element.

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

Sidebar

Related Questions

I have the following xpath query which seems to be working but I just
i am working with an xml, using simplexml and xpath now when i echo
I am working on asp.net application. I have a function like this: Public Function
I have a function that gets a string passed to it. When testing the
I am working on a page that uses XPATH to traverse an XML document
I've got the following XPath expression's working in firebug, that returns the correct element(s):
I have the following Java code working with XPath to get data from XML
I'm working on a scraper using xpath, but xpath seems inexplicably incapable of retreiving
I am trying to do a foreach using xPath. It's working fine and looping
Having looked at various popular modules for working with XML / XPath I have

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.