c# - Content of NextSibling not being printed out -
i have piece of code, , can't figure out why it's not printing out content of next container.
htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument(); doc.load("billing106.htm"); foreach (htmlnode div in doc.documentnode.selectnodes("//div[starts-with(., ' semantic:')]")) { richtextbox1.text += "sc: " + div.nextsibling.innertext.tostring(); }
i have several entries in html file followed:
<div style="top: 232px; left: 332px;" class="s4"> semantic:</div> <div style="top: 233px; left: 377px;" class="s3"> sbr02 specifies relationship person insured.</div>
i can't check class="s3" there multiple items using same class.
if has idea how make work, appreciated, want go home , enjoy weekend, i'll sure send e-beer, hehe.
note: print out 3 times "sc: " occurs 3 times in document.
that's because next sibling of div element not other div, text between 2 divs (yes, nodes too). if want next sibling of div type, should do:
htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument(); doc.load("billing106.htm"); foreach (htmlnode div in doc.documentnode.selectnodes("//div[starts-with(., ' semantic:')]")) { richtextbox1.text += "sc: " + div.selectsinglenode("following-sibling::div").innertext.tostring(); }
see here explanation of xpath axes: xpath axes
Comments
Post a Comment