htmlagilitypack getting an element's node by the name

c# html html-agility-pack

Question

How can I get the node of an element by the name. There is GetElementById, why no GetElementByName. The element in question is:

   <select class="box1" name="DAY" tabindex="31"> … </select>

I want to be able to get this node. But I have no idea how.

Pete: please remove that this question has been answered. It is totally WRONG go try it yourself. the node.Name is not the name of the attribute 'name' its the tagname which is NOT what I need.

Popular Answer

You are not accessing the node attribute called "name" of the "select" tags in the descendants. You are using the property Name of the tag (xe.Name). The correct approach can be :

document.DocumentNode.Descendants("select").Where(node => node.GetAttributeValue("name", "").Equals("DAY", StringComparison.InvariantCultureIgnoreCase));



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why