Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If in your situation you always have exactly three 'pieces', separated by <code>br</code>s, you can use this XPath to get the middle 'piece':</p> <pre><code>//node()[preceding::br and following::br] </code></pre> <p>which uses the <code>preceding</code> and <code>following</code> axes to return all nodes between two <code>br</code>s, anywhere at all.</p> <p><em>edit</em> this is my test app (please excuse the <code>XmlDocument</code>, I am still working with .NET 2.0...)</p> <pre><code>using System; using System.Xml; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { XmlDocument doc = new XmlDocument(); doc.LoadXml(@" &lt;x&gt; &lt;h3&gt;Section title&lt;/h3&gt; &lt;p&gt; &lt;b&gt;Component A&lt;/b&gt;&lt;br /&gt; Component B &lt;i&gt;includes&lt;/i&gt; &lt;strong&gt;multiple elements&lt;/strong&gt;&lt;br /&gt; Component C &lt;/p&gt; &lt;/x&gt; "); XmlNodeList nodes = doc.SelectNodes( "//node()[preceding::br and following::br]"); Dump(nodes); Console.ReadLine(); } private static void Dump(XmlNodeList nodes) { foreach (XmlNode node in nodes) { Console.WriteLine(string.Format("--&gt;{0}&lt;---", node.OuterXml)); } } } } </code></pre> <p>And this is the output:</p> <pre><code>--&gt; Component B &lt;--- --&gt;&lt;i&gt;includes&lt;/i&gt;&lt;--- --&gt;includes&lt;--- --&gt;&lt;strong&gt;multiple elements&lt;/strong&gt;&lt;--- --&gt;multiple elements&lt;--- </code></pre> <p>As you can see, you get an <code>XmlNodeList</code> with all the stuff between the <code>br</code>s.</p> <p>The way I think about it is: This XPath returns any node anywhere, so long as <em>for that node</em>, the preceding axis contains a <code>br</code>, <strong>and</strong> the following axis contains a <code>br</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload