title: Parse XMLns file response PHP
body: <p>I am trying to parse a response from a server but I am struggling with getting the information I want. I am trying to parse and save the username, username1234, to a variable, but I cannot parse it correctly and I am unsure of what I am doing wrong. </p>
  
  <p>From using cUrl</p>
  
  <pre><code>    $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $cas_url);
      curl_setopt($ch, CURLOPT_SSLVERSION, 6);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $response = curl_exec($ch);
      echo nl2br("\nReply from curl: ").htmlentities($response);
      curl_close( $ch );
  </code></pre>
  
  <p>or file_get_contents</p>
  
  <pre><code>$resp = file_get_contents(htmlentities($cas_url));
  </code></pre>
  
  <p>I obtain the following:</p>
  
  <pre><code>&lt;cas:serviceResponse xmlns:cas='http://somesite.edu'&gt; 
  &lt;cas:authenticationSuccess&gt; &lt;cas:user&gt;username1234&lt;/cas:user&gt; 
  &lt;/cas:authenticationSuccess&gt; &lt;/cas:serviceResponse&gt;
  </code></pre>
  
  <p>I have attempted to parse it using DOM where I saved the above reply to $xml but it returns nothing. </p>
  
  <pre><code>$dom = new DomDocument();
  $dom-&gt;loadXML($xml);
  $xpath = new DomXPath($dom);
  $node = $xpath-&gt;query("//cas:user");
  if ($node-&gt;length) {
      echo $node[0]-&gt;textContent;
  }
  </code></pre>
  
  <p>I have also tried registerXPathNamespace since I noticed it replied with xmlns, but I am sure I have done it incorrectly:</p>
  
  <pre><code>$XML_Obj = new SimpleXMLElement($response);
      $XML_Obj -&gt; registerXPathNamespace('cas','http://www.yale.edu/tp/cas');
      foreach($XML_Obj-&gt;xpath('//cas:user') as $event){
          var_export($event-&gt;xpath('cas:serviceResponse'));
      }
  </code></pre>