c# - XPath query not working -


hello making httpwebresponse , getting htmlpage data need example table date info need save them array list , save xml file

example of html page

<tbody>     <tr class="odd">     <tr class="even">     <td class="padding5 sorting_1">     <span class="datehover" sort="14/03/18/22/56" title="18.03.14" ref="18.03.14">18.03.14</span>     </td>     <td class="cellstyledefaulttext">     <span class="transspan">info</span>     </td>     <td class="cellstyledefaulttext" title="usernumber123">usernumber123</td>     <td class="cellstylesignednumber floatophomepage">     <span title="701,554.23 ">701,554.23 </span>     </td>     <td class="cellstyleamount cellstyleamountnew">     <div title="-3354999.71">-3354999.71</div>     </td>     <td class="cellstyledetails ccmoredetailstd">     <span> 17.03.14 info</span>     </td>     </tr>     </tbody> 

ok first span datetime got

foreach (htmlnode node in doc.documentnode.selectnodes("//span[@class='datehover']")) 

span info

foreach (htmlnode node in doc.documentnode.selectnodes("//td[@class='transspan']")) 

and stuck usernumber123 did this

foreach (htmlnode node in doc.documentnode.selectnodes("//td[@class='cellstyledefaulttext']")) 

but returns me span transspan because in td

and others td cellstylesignednumber,cellstyleamount,cellstyledetails can't get.

any ideas?

you can mention attribute name select element has particular attribute set. can try usernumber123 way :

doc.documentnode.selectnodes("//td[@class='cellstyledefaulttext' , @title]") 

above xpath means, select <td> element has title attribute , hass class attribute value equals 'cellstyledefaulttext'.

for rest <td>, try use xpath contains() function, example :

doc.documentnode.selectnodes("//td[contains(@class,'cellstylesignednumber')]") 

update :

responding latter part of comment, if intend <td> has child <span>element, can add criteria simple following :

doc.documentnode.selectnodes("//td[span , contains(@class,'cellstylesignednumber')]") 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -