Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Get element by ID #477

Open
Ebola-Chan-bot opened this issue May 30, 2022 · 6 comments
Open

[Feature request] Get element by ID #477

Ebola-Chan-bot opened this issue May 30, 2022 · 6 comments

Comments

@Ebola-Chan-bot
Copy link

It's 2022 now and I don't know why you still don't have such a basic function: directly search an element by its ID, instead of having to know its actual path.

If you already have such a function then forgive me for not finding the relevant instructions in your documentation.

@tewuapple

This comment was marked as spam.

@elgonzo
Copy link
Contributor

elgonzo commented May 30, 2022

It's 2022 now and I don't know why you still don't have heard about such basic things like XPath queries. 😘

HAP has a function for XPath queries: https://html-agility-pack.net/select-nodes

XPath queries can be used to find/select nodes in a HTML (or XML) document by a variety of criteria, like for example to find element(s) with an id attribute having a certain value. For example, if you want to find any kind of element with an id "foobar", you could use the XPath query //*[@id='foobar'].

(I am not affiliated in any way with the HAP project. Just a user using the library in a couple of my projects...)

@Ebola-Chan-bot
Copy link
Author

Ebola-Chan-bot commented May 30, 2022

It's 2022 now and I don't know why you still don't have heard about such basic XML-related things like XPath queries. ;-)

HAP has a function for XPath queries: https://html-agility-pack.net/select-nodes

XPath queries can be used to find/select nodes in a XML document by a variety of criteria, like for example to find element(s) with an id attribute having a certain value. For example, if you want to find any kind of element with an id "foobar", you could use the XPath query //*[@id='foobar'].

(I am not affiliated in any way with the HAP project. Just a user using the library in a couple of my projects...)

Sorry, I'm really not very familiar with XPath.
But I have also investigated some of your well-known competing products, such as Aspose.HTML, AngleSharp, etc. They all straightforwardly provide the GetElementById function and do not require users to understand XPath.
I believe HAP would be more attractive if this function is added, since you specified HTML, where the ID attribute is specially defined, instead of a more general XML in the package title.

@elgonzo
Copy link
Contributor

elgonzo commented May 30, 2022

some of your well-known competing products

In case it got missed what i wrote at the end of my last comment: I am not representing the HAP project. I am not affiliated with the HAP project in any way.

Looking around a bit in the code base of HAP, its HtmlDocument class already has a GetElementById method:

/// <summary>
/// Gets the HTML node with the specified 'id' attribute value.
/// </summary>
/// <param name="id">The attribute id to match. May not be null.</param>
/// <returns>The HTML node with the matching id or null if not found.</returns>
public HtmlNode GetElementbyId(string id)

For reasons unknown to me, it's not appearing in the online documentation as far as i can tell. But then again, there is no real online API documentation of most of HAP's functionality anyway, so i guess it's par for the course with respect to HAP's documentation... 😕

@Ebola-Chan-bot
Copy link
Author

some of your well-known competing products

In case it got missed what i wrote at the end of my last comment: I am not representing the HAP project. I am not affiliated with the HAP project in any way.

Looking around a bit in the code base of HAP, its HtmlDocument class already has a GetElementById method:

/// <summary>
/// Gets the HTML node with the specified 'id' attribute value.
/// </summary>
/// <param name="id">The attribute id to match. May not be null.</param>
/// <returns>The HTML node with the matching id or null if not found.</returns>
public HtmlNode GetElementbyId(string id)

For reasons unknown to me, it's not appearing in the online documentation as far as i can tell. But then again, there is no real online API documentation of most of HAP's functionality anyway, so i guess it's par for the course with respect to HAP's documentation... 😕

Then this issue becomes to add the documentation …
Many people won't bother to download it if they can't find the function they want in the documentation, especially when there're many other options.

@elgonzo
Copy link
Contributor

elgonzo commented May 30, 2022

Then this issue becomes to add the documentation …

True.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants