-
-
Notifications
You must be signed in to change notification settings - Fork 579
GetAttributeNode extension methods added to Element #1223
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
Conversation
In general this is great, but it would be breaking in a way that users that implemented from A nice way out here would be to instead use something like For instance: [DomName("getAttributeNode")]
public static IAttr? GetAttributeNode(this IElement element, String name)
{
if (NamespaceUri.Is(NamespaceNames.HtmlUri))
{
name = name.HtmlLower();
}
return Attributes.GetNamedItem(name);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds two new methods, GetAttributeNode, to the IElement interface and its implementation, allowing attribute retrieval by name or by namespace and local name.
- Added GetAttributeNode(string name) and GetAttributeNode(string? namespaceUri, string localName) in the Element implementation.
- Updated the IElement interface to expose the new methods with corresponding documentation and DOM names.
- Added tests in DOMActions.cs to verify behavior for namespaced and non-namespaced attribute retrieval.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/AngleSharp/Dom/Internal/Element.cs | Added implementations for GetAttributeNode methods with handling for HTML namespace. |
src/AngleSharp/Dom/IElement.cs | Defined interface for new GetAttributeNode methods with XML documentation and DOM names. |
src/AngleSharp.Core.Tests/Library/DOMActions.cs | Added tests to validate the behavior of the new attribute retrieval methods. |
Yes - you're right. I'll try to fix it tomorrow. |
Do you think new file would be better than using already existing What do you think? |
I agree. A new file would be cleaner imho, too. |
Done. Let me know if it looks ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks for the wonderful work!
Types of Changes
Prerequisites
Please make sure you can check the following two boxes:
Contribution Type
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Description
GetAttributeNode(name) and GetAttributeNode(namespace, localName) added to IElement. Resolves #1221.