【发布时间】:2014-03-12 13:08:55
【问题描述】:
我正在尝试拆分 XML 字符串,如下所示:
<root>
<item attr='test'>test1</item>
<anotherItem>test2</anotherItem>
<item3><t>Title</t><foo></foo></item3>
</root>
我希望数组看起来像:
$arrXml[0] = "<item attr='test'>test1</item>";
$arrXml[1] = "<anotherItem>test2</anotherItem>";
$arrXml[2] = "<item3><t>Title</t><foo></foo></item3>";
我已经查看了Split XML in PHP 中的解决方案,但它们仅适用于只有“项目”节点的 XML 文档。
我尝试过使用 XmlReader,但在使用 read() 之后,如何获取当前节点,包括它自己的带有属性的 xml? readOuterXml() 似乎不起作用,只输出内部值。
xml 不包含\n,所以我不能使用explode()。
【问题讨论】: