title: PHP SimpleXMLIterator
body: <p>I am using SimpleXMLIterator to parse some XML.
  Doing a print_r shows that the SimpleXMLIterator Object created from the XML is like this:
  {</p>
  
  <pre><code>[@attributes] =&gt; Array
      (
          [id] =&gt; abc
          [type] =&gt; a
          [timestamp] =&gt; 2001-12-12
      )
  
  [place] =&gt; US
  [name] =&gt; Pete
  [dob] =&gt; SimpleXMLIterator Object
      (
          [dd] =&gt; 03
          [mm] =&gt; 05
          [yyyy] =&gt; 1973
      )
  </code></pre>
  
  <p>}</p>
  
  <p>which also contains a dob SimpleXMLIterator Object - i.e. a child element of the XML tag.</p>
  
  <p>I iterate over this object using the following code, which is recurive as i cant be sure how deep each XML tag goes:</p>
  
  <pre><code>function _prepareSimpleXMLIteratorObj(SimpleXMLIterator $xmlIterator) {
  
  foreach ($xmlIterator as $key =&gt; $value){
      // Count returns the number of children
      if ($value-&gt;count() &gt; 0) {      
          $this-&gt;_prepareSimpleXMLIteratorObj($value);
      } else {
          $this-&gt;assocArray[$key] = (string)$value;
      }
  }
  }
  </code></pre>
  
  <p>assocArray is a member variable of the class.
  This generates an assoc array from the Object.</p>
  
  <p>Problem is when i use $value->hasChildren() instead of $value->count() i get false, even though $value->count() returns 3 for dob? Any ideas what i;m doing wrong?
  Also if is do </p>
  
  <pre><code>if (($value instanceof SimpleXMLIterator))
  </code></pre>
  
  <p>i get false, even though dob is clearly a SimpleXMLIterator Object?</p>
  
  <p>This method works but am just wondering about hasChildren and instanceof?</p>
  
  <p>Here is the Sample XML</p>
  
  <pre><code>&lt;tag id="abc" type="a" timestamp="2001-12-12"&gt;
      &lt;place&gt;US&lt;/place&gt;
      &lt;name&gt;Pete&lt;/name&gt;
      &lt;dob&gt;
          &lt;dd&gt;03&lt;/dd&gt;
          &lt;mm&gt;05&lt;/mm&gt;
          &lt;yyyy&gt;1973&lt;/yyyy&gt;
      &lt;/dob&gt;
  &lt;/tag&gt;
  </code></pre>
  
  <p>Thanks</p>