xpath - How do I find attributes starting with a specifc value using HTML Agilty Pack? -


i trying find attributes within html document start particular value. seem have valid xpath query returns nothing when using html agility pack.

i'm aware using linq i'm attempting reuse existing functionality , leverage xpath query.

example html

<!doctype html> <html> <head> <title>title</title> </head> <body> <p>loren ipsum</p> <a href="http://www.myurl.com" onclick="myfunction()"></a> </body> </html> 

xpath query

//*/@*[starts-with(name(), 'on')] 

is possible in html agility pack?

using htmlagilitypack (hap) , xpath function name() didn't work me, replacing name() local-name() did trick :

//*/@*[starts-with(local-name(), 'on')] 

however, both selectsinglenode() , selectnodes() able return htmlnode(s). when xpath expression selects attribute instead of node, attribute's owner node returned. in end still need attribute through options besides xpath, example :

htmldocument doc; ...... var link = doc.documentnode               .selectsinglenode("//*/@*[starts-with(local-name(), 'on')]"); var onclick = link.attributes                   .first(o => o.name.startswith("on")); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -