xpath - HTMLAgilitliyPack: select Form input subnodes not working -


form:

<form method="post" name="contactform" action="form-handler.php">       <label for='name'>name:</label>      <input type="text" name="name" />      <label for='email'>contact number:</label>      <input type="text" name="phone" />       <label for='phone'>email:</label>      <input type="text" name="email" />       <label for='message'>requirements:</label>       <textarea name="message"></textarea>      <input type="submit" value="submit" name="submit" class="quotebutton" />  </form> 

code:

        htmlnode.elementsflags.remove("form");         htmlnodecollection fromnodes = doc.documentnode.selectnodes("//form");         foreach (htmlnode formnode in fromnodes)         {             var inputs = formnode.selectnodes(".//input");         } 

"//input" works , when check children xpath see:

/html[1]/body[1]/div[1]/div[3]/div[2]/div[1]/div[1]/input[2] 

which means, according hap, form doesn't include input!

".//input" selects subnodes of current formnode doesn't work (returns null)!

how fix added following doesn't work

 htmlnode.elementsflags.remove("form");  

any idea?

edit (+example):

in next sample inputs variable null.

        var doc = new htmldocument();         doc.loadhtml(@"             <!doctype html>             <html>                 <head>                     <title>form test</title>                 </head>                 <body>                     <form>                         <input type=""text"" />                         <input type=""reset"" />                         <input type=""submit"" />                     </form>                 </body>             </html>             ");          htmlnode.elementsflags.remove("form");         ienumerable<htmlnode> fromnodes = doc.documentnode.descendants("form");         foreach (htmlnode formnode in fromnodes)         {             var inputs = formnode.selectnodes(".//input");         } 

solved!

        htmlnode.elementsflags.remove("form"); 

should called before loading document.

my bad :d


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -