title: Using XPath to select certain nodeName
body: <p>I followed the tutorial on W3Schools.</p>
  
  <p><a href="http://www.w3schools.com/xpath/xpath_syntax.asp" rel="nofollow noreferrer">http://www.w3schools.com/xpath/xpath_syntax.asp</a></p>
  
  <p>It says:</p>
  
  <blockquote>
    <p>nodename  Selects all child nodes of
    the named node</p>
    
    <p>bookstore Selects all the child nodes
    of the bookstore element</p>
  </blockquote>
  
  <p>and here's my code</p>
  
  <p>bookstore.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
      &lt;bookstore&gt;
      &lt;book&gt;
        &lt;title lang="eng"&gt;Harry Potter&lt;/title&gt;
        &lt;price&gt;29.99&lt;/price&gt;
      &lt;/book&gt;
      &lt;book&gt;
        &lt;title lang="eng"&gt;Learning XML&lt;/title&gt;
        &lt;price&gt;39.95&lt;/price&gt;
      &lt;/book&gt;
      &lt;/bookstore&gt;
  </code></pre>
  
  <p>the php file:</p>
  
  <pre class="lang-php prettyprint-override"><code>    &lt;?php
      $xml = simplexml_load_file("bookstore.xml");
      if(!$xml)
      { 
      echo 'bad';
      }else
      {
  
      $res = $xml-&gt;xpath("//bookstore");
  
      when I use $res = $xml-&gt;xpath("bookstore");
      $xml_res1 = $res1-&gt;asXML("booklist.xml");
      }
      ?&gt;
  </code></pre>
  
  <p>It only returns an empty array.
  I want to select all of the <code>&lt;book&gt;</code> elements only (not to include the <code>&lt;bookstore&gt;</code> and the <code>&lt;?xml version?&gt;</code> header)</p>
  
  <p>In the W3Schools example, the "//bookstore" can select all the child nodes of the bookstore element.</p>
  
  <p>Can anybody tell me why I got an empty array? Thanks!</p>