title: PHP DOM : getElementsbyTagName
body: <p>I fear that this is a really stupid question but I am really stuck after trying a load of combinations for the last 2 hours. I am trying to pull the NAME out of the XML file</p>
  
  <p>My XML file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;userdata&gt;
  &lt;name&gt;John&lt;/name&gt;
  &lt;/userdata&gt;
  </code></pre>
  
  <p>My php:</p>
  
  <pre><code>  $doc          =  new DOMDocument();
    $doc          -&gt; load( "thefile.xml" );
    $thename       =  $doc -&gt; getElementsByTagName( "name" );
  $myname= $thename -&gt; getElementsByTagName("name") -&gt; item(0) -&gt; nodeValue;
  </code></pre>
  
  <p>The Error:</p>
  
  <pre><code>Catchable fatal error: Object of class DOMElement could not be converted to string in phpreader.php
  </code></pre>
  
  <p>I have tried </p>
  
  <pre><code>$myname= $thename -&gt; getElementsByTagName("name") -&gt; item(0) ;
  $myname= $doc     -&gt; getElementsByTagName("name") -&gt; item(0) -&gt; nodeValue;
  $myname= $doc     -&gt; getElementsByTagName("name") -&gt; item(0) ;
  </code></pre>
  
  <p>but all fail. Guess I have tried just about every combination except the correct one :(</p>