SelectSingleNode Html Document

c# html-agility-pack nullreferenceexception

Question

I'm working with an HTMLDocument in C# that came from a website right now:

return doc.DocumentNode.SelectSingleNode("//span[@title=input]").InnerText;

From a span with the title "input," I want to get the inner text. This is my current code, however when I attempt to execute it, I get a NullReferenceException. What implicit parameter has to be used in order to get the text from "input"?

1
1
10/24/2012 7:12:26 PM

Accepted Answer

return doc.DocumentNode.SelectSingleNode("//span[@title='"+input+"']").InnerText;

The input must be concatenated in order to accommodate the parameters since it is not a string. Many thanks for your assistance!

0
10/25/2012 6:49:23 PM

Popular Answer

In XPath expressions, you must use quotes to separate strings:

return doc.DocumentNode.SelectSingleNode("//span[@title='input']").InnerText;

Plain input will attempt to find a node with that name and replace its value.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow