XML解析:使用通配符解析XML


PHP:XML parse: Parsing xml with wildcard

我有这样的XML

<items>                    
 <item>SREE</item>
  .. 
  ..
 <item>ABC</item>
</items>

<items>
<section name='1'>
<item>AA</item>
<item>AA</item>
<item>AA</item>
<item>AA</item>
</section>
<section name='2'>
<item>AA</item>
..
..
</section>
..
..
</items>

我必须解析该xml中的所有item标签。我在xml解析器中使用通配符,比如

$itemName = $items->xpath("items/*/item");

这只是解析第二个xml。我想写一个函数,它可以从上述所有xml中获取项目名称。请告诉我最好的方法

有两种可能:

1)如果结构重要,则使用与|分隔的两条位置路径。

items/section/item | items/item

2)使用后代轴获取任何级别物品中的任何物品

items//item

这是

的缩写
items/descendant::item