title: Parse XML file for specific tag to get the content of a sibling tag
body: <p>I have this XML file: </p>
  
  <pre><code>   &lt;page&gt;
        &lt;title&gt;test&lt;/title&gt;
        &lt;text&gt;bla bla&lt;/text&gt;
     &lt;/page&gt;
     &lt;page&gt;
        &lt;title&gt;another test&lt;/title&gt;
        &lt;text&gt;bla bla&lt;/text&gt;
      &lt;/page&gt;
      &lt;page&gt;
        &lt;title&gt;hello&lt;/title&gt;
        &lt;text&gt;hello world&lt;/text&gt;
      &lt;/page&gt;
  </code></pre>
  
  <p>I want to parse the file (PHP SAX parser) to find pages with the Title "hello", and then save the corresponding Text tag content.. what I did so far is this: </p>
  
  <pre><code>   $pages = array();
     $elements  = null;
  
     function startElements($parser, $name, $attrs) {
        global $wiki, $elements;
  
        if(!empty($name)) {
          $elements = $name;
        }
     }
  
     function endElements($parser, $name) {
        global $elements;
  
        if(!empty($name)) {
           $elements = null;
        }
     }
  
     function characterData($parser, $data) {
        global $pages, $elements;
  
        if(!empty($data)) {
           if ($elements == 'TITLE' ) {
              if((preg_match('/Hello/', $data)==1))
               { 
  
                   // ... I found the page with the good title, but how to get the following text tag content!!
  
               }
           }
        }
     }
  
     $parser = xml_parser_create(); 
  
     xml_set_element_handler($parser, "startElements", "endElements");
     xml_set_character_data_handler($parser, "characterData");
  
    if (!($handle = fopen('tmp.xml', "r"))) {
        die("could not open XML input");
     }
  
     while($data = fread($handle, 4096)) {
        xml_parse($parser, $data);  
     }
  </code></pre>
  
  <p>Any ideas on how to get the content of the Text tag with specific Titles tag? I could get the result I need by saving all the data in an array.. and then to the search !! but I'd like a better solution.</p>
  
  <p>thank you.</p>