title: Split XML nodes into php array
body: <p>I'm trying to split an XML string, like this:</p>
  
  <pre><code>&lt;root&gt;
    &lt;item attr='test'&gt;test1&lt;/item&gt;
    &lt;anotherItem&gt;test2&lt;/anotherItem&gt;
    &lt;item3&gt;&lt;t&gt;Title&lt;/t&gt;&lt;foo&gt;&lt;/foo&gt;&lt;/item3&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I want the array to look like:</p>
  
  <pre><code>$arrXml[0] = "&lt;item attr='test'&gt;test1&lt;/item&gt;";
  $arrXml[1] = "&lt;anotherItem&gt;test2&lt;/anotherItem&gt;";
  $arrXml[2] = "&lt;item3&gt;&lt;t&gt;Title&lt;/t&gt;&lt;foo&gt;&lt;/foo&gt;&lt;/item3&gt;";
  </code></pre>
  
  <p>I already looked at the solutions in <a href="https://stackoverflow.com/questions/4022085/split-xml-in-php">Split XML in PHP</a> but they only work for an XML document with only "item" nodes. </p>
  
  <p>I've tried using XmlReader but after I use read(), how can I get the current node including its own xml with attributes? readOuterXml() doesn't seem to work and only outputs the inner value.</p>
  
  <p>The xml doesn't contain \n so I can't use explode().</p>