I'm trying to split an XML string, like this:
<root>
<item attr='test'>test1</item>
<anotherItem>test2</anotherItem>
<item3><t>Title</t><foo></foo></item3>
</root>
I want the array to look like:
$arrXml[0] = "<item attr='test'>test1</item>";
$arrXml[1] = "<anotherItem>test2</anotherItem>";
$arrXml[2] = "<item3><t>Title</t><foo></foo></item3>";
I already looked at the solutions in Split XML in PHP but they only work for an XML document with only "item" nodes.
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.
The xml doesn't contain \n so I can't use explode().