HtmlAgilityPack how to extract html between some tag
<p>I need to extract all the paragraph from one html and also all text between that tags.</p>

<p>this code is not working when the text parsed into HtmlDocument get changed from the original one. In the sample </p>

<pre><code>some &lt;br /&gt;text
</code></pre>

<p>is changed in</p>

<pre><code>some &lt;br&gt;text
</code></pre>

<p>es:</p>

<pre><code>string s = "&lt;p&gt;firt paragraph&lt;/p&gt;some &lt;br /&gt;text&lt;p&gt;another paragraph&lt;/p&gt;&lt;span&gt;some text between span&lt;/span&gt;&lt;p&gt;hellow word&lt;/p&gt;";
        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(s);
var nodes = doc.DocumentNode.SelectNodes("//p");
int lastPos = -1;
foreach (HtmlAgilityPack.HtmlNode n in nodes)
{
  if (lastPos &gt; -1)
  {
      string textNotInP = Doc.DocumentNode.OuterHtml.Substring(lastPos, n.StreamPosition - lastPos);
                System.Diagnostics.Debug.WriteLine(textNotInP);
 }
 System.Diagnostics.Debug.WriteLine(n.OuterHtml);
 lastPos = n.StreamPosition + n.OuterHtml.Length;
}
</code></pre>

<p>the correct result would be:</p>

<pre><code>&lt;p&gt;firt paragraph&lt;/p&gt;
some &lt;br&gt;text
&lt;p&gt;second paragraph&lt;/p&gt;
&lt;span&gt;some text between span&lt;/span&gt;
&lt;p&gt;third paragraph&lt;/p&gt;
</code></pre>

<p>but the code above return this:</p>

<pre><code>&lt;p&gt;firt paragraph&lt;/p&gt;
some &lt;br&gt;text&lt;p
&lt;p&gt;second paragraph&lt;/p&gt;
pan&gt;some text between span&lt;/span&gt;&lt;p
&lt;p&gt;third paragraph&lt;/p&gt;
</code></pre>

<p>the reason is steamPosition return the node position related to the original text, not that one parserd in htmlDocument.</p>

<p>Is There a way to return the position of one node related to the parsed html?</p>