1

I am trying to get the inner text from a node but it has child nodes and its text is in the middle of its child entries i.e:

<script1>
 <p1>lalala</p1>
 "script text"
</script1>

The code I need is inside script1, but if I try and get innertext I get all of the inside of p1 too..

Cannot figure it out.

madth3
  • 7,275
  • 12
  • 50
  • 74
Aaron Gibson
  • 1,280
  • 1
  • 21
  • 36
  • 1
    http://stackoverflow.com/questions/12092575/html-agility-pack-remove-element-but-not-innerhtml – Karthik Dec 19 '12 at 07:42

1 Answers1

1

This code:

    HtmlDocument doc = new HtmlDocument();
    doc.Load(MyTextHtml);

    HtmlNode node = doc.DocumentNode.SelectSingleNode("//p1/following-sibling::text()");
    Console.WriteLine(node.InnerText.Trim());

will output this:

"script text"

Here is link on XPATH axes that should get you started.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298