title: Get Information of nodes in context with PHP XML Reader
body: <p>@those who marked this question as duplicate, please leave a comment why you think this is. Here, we want to get all elements in a certain node. In the other Question they want to get the parent node. This is almost the opposite. Here we are not selecting the people node and its children but rather get ever person within a context. I see it might look similar.</p>
  
  <p>Question:
  To be clear: I want to do this with XML Reader.</p>
  
  <p>I have got an XML-file and want to retrieve the content of the name-node within the context people. The name-node also appears in cars, that's why I need the context.</p>
  
  <p>How can I do this?</p>
  
  <pre><code>&lt;file&gt;
    &lt;people&gt;
       &lt;person&gt;
          &lt;name&gt;father&lt;/name&gt;
          &lt;age&gt;50&lt;/age&gt;
       &lt;/person&gt;
    &lt;/people&gt;
    &lt;car&gt;
       &lt;person&gt;
          &lt;name&gt;mom&lt;/name&gt;
          &lt;age&gt;45&lt;/age&gt;
       &lt;/person&gt;
       &lt;name&gt;Octavia&lt;/name&gt;
       &lt;brand&gt;Scoda&lt;/brand&gt;
    &lt;/car&gt;
    &lt;people&gt;
       &lt;person&gt;
          &lt;name&gt;son&lt;/name&gt;
          &lt;age&gt;25&lt;/age&gt;
       &lt;/person&gt;
       &lt;person&gt;
          &lt;name&gt;daughter&lt;/name&gt;
          &lt;age&gt;20&lt;/age&gt;
       &lt;/person&gt;
    &lt;/people&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the PHP I got so far:</p>
  
  <pre><code>$xmlReader = new XMLReader;
  
  if (!$xmlReader-&gt;open($this-&gt;_file, null, 1&lt;&lt;19)) {
     die("Failed to open file");
  }
  
  
  while($xmlReader-&gt;read()) {
      // set the context
      if ($xmlReader-&gt;nodeType == XMLReader::ELEMENT &amp;&amp; $xmlReader-&gt;name == 'people') {
            // do something with the name of every person
            if ($xmlReader-&gt;nodeType == XMLReader::ELEMENT &amp;&amp; $xmlReader-&gt;name == 'person') {
                $xmlReader-&gt;name-&gt;readString();
            }
      }
  }
  </code></pre>