Skip to content Skip to sidebar Skip to footer

Get Fields From A Form In Htmlagilitypack

I want to get the data for a form so i wrote the below. It didnt work doc.DocumentNode.SelectNodes('//form[@name='F1']//input[@name]'); Breaking it up into two steps did var node

Solution 1:

It seems this is default behavior for <form> tag parsing in Html Agility Pack. As they said here:

FORM is treated like this because many HTML pages used to have overlapping forms, as this was actually a (powerful) feature of original HTML. Now that XML and XHTML exist, everybody assumes that overlapping is an error, but it's not (in HTML 3.2).

You could change it by using:

HtmlNode.ElementsFlags.Remove("form");

and your "//form[@name='F1']//input[@name]" expression should work. Or change the second expression to ".//input[@name]" and it also should work:

var node = doc.DocumentNode.SelectSingleNode("//form[@name='F1']");
var nodes = node.SelectNodes(".//input[@name]");

Post a Comment for "Get Fields From A Form In Htmlagilitypack"