title: How to create new XML from xpath result with simplexml?
body: <p><strong>Here's my XML-snippet:</strong></p>
  
  <pre><code>&lt;foo&gt;
      &lt;bar&gt;
          &lt;id&gt;120034&lt;/id&gt;
          &lt;name&gt;Tom&lt;/name&gt;
      &lt;/bar&gt;
      &lt;bar&gt;
          &lt;id&gt;9088812&lt;/id&gt;
          &lt;name&gt;Tom&lt;/name&gt;
      &lt;/bar&gt;
      &lt;bar&gt;
          &lt;id&gt;140034&lt;/id&gt;
          &lt;name&gt;Mike&lt;/name&gt;
      &lt;/bar&gt;
  &lt;/foo&gt;
  </code></pre>
  
  <p><strong>Here's my PHP</strong> to extract all <code>bar/name = Tom</code>:  </p>
  
  <pre><code>$xml = simplexml_load_string($x); // XML assumed in $x
  
  $results = $xml-&gt;xpath("/foo/bar[name = 'Tom']");
  </code></pre>
  
  <p><strong>Problem:</strong> How to make a new XML from <code>$results</code>?</p>
  
  <p>I tried</p>
  
  <pre><code>$results-&gt;asXML();
  </code></pre>
  
  <p>but I got the error that <code>$results</code>is not a simplexml-object.</p>