title: How to retrive recursive element from XML using XPath
body: <p>While working on the Xpath Expressions, i stuck in one case, where i have to find out the node, which is dependent on the other node's one element. </p>
  
  <p>Below is the XML example used :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  
  &lt;parent1&gt;
      &lt;child1 id="1"&gt;
          &lt;in&gt;Starting1&lt;/in&gt;
          &lt;out&gt;connect1&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="2"&gt;
          &lt;in&gt;connect1&lt;/in&gt;
          &lt;out&gt;connect1.1&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="3"&gt;
          &lt;in&gt;Starting2&lt;/in&gt;
          &lt;out&gt;connect2&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="4"&gt;
          &lt;in&gt;connect1.1&lt;/in&gt;
          &lt;out&gt;connect1.2&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="5"&gt;
          &lt;in&gt;connect1.2&lt;/in&gt;
          &lt;out&gt;end1&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="6"&gt;
          &lt;in&gt;connect2&lt;/in&gt;
          &lt;out&gt;connect2.1&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="7"&gt;
          &lt;in&gt;connect2.1&lt;/in&gt;
          &lt;out&gt;connect2.2&lt;/out&gt;
      &lt;/child1&gt;
      &lt;child1 id="8"&gt;
          &lt;in&gt;connect2.2&lt;/in&gt;
          &lt;out&gt;open2&lt;/out&gt;
      &lt;/child1&gt;
  &lt;/parent1&gt;
  </code></pre>
  
  <p>Desired output is to find out the node, which is having starting point as "Starting" and then travel to another node ( means, out of node is In for other node) &amp; Not ending in "end".</p>
  
  <p>There might be x number of connections between Starting and end.</p>
  
  <p>I have used following xpath expression. But this is limited to 2 level of recursion. </p>
  
  <pre><code>//parent1/child1[in=(//parent1/child1[in=(//parent1/child1[in=(//parent1/child1[contains(in,"Starting")]/out)]/out)]/out) and not(contains(out,"end"))]
  </code></pre>
  
  <p>Output :  </p>
  
  <pre><code>&lt;child1 id="8"&gt;
    &lt;in&gt;connect2.2&lt;/in&gt;
    &lt;out&gt;open2&lt;/out&gt;
  &lt;/child1&gt;
  </code></pre>
  
  <p>As, i am not sure how many number of connectors could be between the nodes. So, is there any way in XML1.0 to find out recursion?</p>
  
  <p>there is a <a href="https://stackoverflow.com/questions/10463934/how-to-retrieve-node-after-node-of-xml-tree-using-xpath">duplicate question already in stackoverflow.</a> But, i didn't get the solution from there. </p>
  
  <p><a href="https://i.stack.imgur.com/dEKdV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dEKdV.png" alt="enter image description here"></a></p>