title: SimpleXML Accessing Elements - PHP
body: <p>I am trying to get inside of <code>&lt;err:Errors&gt;</code> located in the SOAP below.</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soapenv:Header/&gt;
      &lt;soapenv:Body&gt;
          &lt;soapenv:Fault&gt;
              &lt;faultcode&gt;Client&lt;/faultcode&gt;
              &lt;faultstring&gt;An exception has been raised as a result of client data.&lt;/faultstring&gt;
              &lt;detail&gt;
                  &lt;err:Errors xmlns:err="http://www.ups.com/XMLSchema/XOLTWS/Error/v1.1"&gt;
                      &lt;err:ErrorDetail&gt;
                          &lt;err:Severity&gt;Hard&lt;/err:Severity&gt;
                          &lt;err:PrimaryErrorCode&gt;
                              &lt;err:Code&gt;120802&lt;/err:Code&gt;
                              &lt;err:Description&gt;Address Validation Error on ShipTo address&lt;/err:Description&gt;
                          &lt;/err:PrimaryErrorCode&gt;
                      &lt;/err:ErrorDetail&gt;
                  &lt;/err:Errors&gt;
              &lt;/detail&gt;
          &lt;/soapenv:Fault&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>Here is how I am trying to do it but $fault_errors->Errors doesn't have anything.</p>
  
  <pre><code>$nameSpaces = $xml-&gt;getNamespaces(true);
  $soap = $xml-&gt;children($nameSpaces['soapenv']);
  $fault_errors = $soap-&gt;Body-&gt;children($nameSpaces['err']);
  
  if (isset($fault_errors-&gt;Errors)) {
      $faultCode = (string) $fault_errors-&gt;ErrorDetail-&gt;PrimaryErrorCode-&gt;Code;               
  }
  </code></pre>