-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
How to bind a nested class property to the attribute of html element with GetEncapsulatedData Method? #505
Comments
The bug seems to be not adhering to the HtmlNode.Encapsulator.cs#L298:
isn't the only place exhibiting this issue, HtmlNode.Encapsulator.cs#L180 also forgets to take HasXPathAttribute.NodeReturnType into account:
After proper support for the HasXPathAttribute.NodeReturnType property has been implemented, then this should work: [HasXPath]
class TestA
{
[XPath("a", NodeReturnType = ReturnType.OuterHtml)] // <--------- setting NodeReturnType here
public List<Item> Items { get; set; }
[HasXPath]
public class Item
{
[XPath(".", "href")]
[SkipNodeNotFound]
public string Href { get; set; }
[XPath(".")]
[SkipNodeNotFound]
public string Name { get; set; }
}
} |
Side note: There is a related issue that also warrants fixing when the proper NodeReturnType support is being implemented. Currently, when a property of a simple type like string has a
This should to be changed into a meaningful exception with a message that informs about the concrete cause of the exception. |
@elgonzo I created a PR on your advice, please help me review it. |
Hello @rwecho , We will close this issue has your PR has been merged and now available in the v1.11.50 Best Regards, Jon |
html-agility-pack/src/HtmlAgilityPack.Shared/HtmlNode.Encapsulator.cs
Line 298 in c12580b
In most situations, I like to use XPath attribute binding to a Property. But in the nested class, it can not access the parent node, the parent node's attribute often records some important information, like id.
In the HtmlNode.Encapsulator.cs#L298, Is using OuterHtml better than InnerHtml?
The text was updated successfully, but these errors were encountered: