General Solution for Iterating Through PHP SimpleXMLElementObject
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/11137204/parse-xml-sequentially-in-php">Parse XML sequentially in PHP</a>  </p>
</blockquote>



<p>I want to be able to iterate through a SimpleXMLElementObject using PHP. However, I want to be able to do it <em>without</em> knowing the tag names in advance - I want a general solution that can be used as a discovery mechanism for the object's key names. I've tried a bunch of 'foreach' type solutions but can't get it to work.</p>

<p>Example code:</p>

<pre><code>$schema = new SimpleXMLElement("&lt;activity&gt;&lt;/activity&gt;");
$schema-&gt;addAttribute("default-currency","asdf");
$schema-&gt;addAttribute("last-updated-datetime","jkl;");
$schema-&gt;addChild('title', 'example title');
</code></pre>

<p>print_r($schema) gives:</p>

<pre><code>SimpleXMLElement Object ( 
    [@attributes] =&gt; Array ( 
        [default-currency] =&gt; asdf 
        [last- updated-datetime] =&gt; jkl; 
        ) 
    [title] =&gt; example title 
) 
</code></pre>

<p>Thanks</p>
