title: How can I read attributes of a self closing tag using SimpleXML (PHP)
body: <p>I have a XML file containing, among other tags, some self closing tags.</p>
  
  <pre><code>&lt;tagname attr1="foo1" attr2="foo2" /&gt;
  </code></pre>
  
  <p>I use  PHP's simplexml to load the XML file into a object.
  So far so good.</p>
  
  <p>The problem is with the self closing tags. (print_r returns an empty object)</p>
  
  <p>I cannot access their attributes.</p>
  
  <p><strong>====UPDATE====</strong></p>
  
  <p>It worked this way:</p>
  
  <pre><code>$xml = simplexml_load_string($string);
  echo $xml-&gt;tagname['attr1'];
  </code></pre>