【发布时间】:2013-06-10 08:02:56
【问题描述】:
我想对 SimpleXML 对象中的每个节点应用一个函数。
<api>
<stuff>ABC</stuff>
<things>
<thing>DEF</thing>
<thing>GHI</thing>
<thing>JKL</thing>
</things>
</api>
//函数 reverseText($str){};
<api>
<stuff>CBA</stuff>
<things>
<thing>FED</thing>
<thing>IHG</thing>
<thing>LKJ</thing>
</things>
</api>
如何将 reverseText() 应用到每个节点以获取第二个 XML sn-p?
【问题讨论】:
-
这不能是递归的,但遍历 XML 文档顺序 中的所有元素也可以。然而,在 PHP 中,这是作为
SimpleXMLExtension中的RecursiveIterator实现的,可以按照 Salathe 的 SPL 概述使用。另请参阅:en.wikipedia.org/wiki/XML_tree