Home  >  Article  >  Backend Development  >  php xPath 解析xml文件 有关问题

php xPath 解析xml文件 有关问题

WBOY
WBOYOriginal
2016-06-13 13:20:01622browse

php xPath 解析xml文件 问题
说来话长-为了描述的好一些
从前有个xml 文件, 文件内容大致如下:

 
  aaa
  bbb
 

 
  ccc
  ddd
 


很明了,就是可以有若干个collection, 并且在每个collection里包含若干个category.并且collection和category的id都是唯一的, 以前我在修改category的node value的时候. 一直是用xpath 例如:把id为ca1的category的值改掉,我就可以
$xpath->query("/root/collection/category[@id='"ca1"']"); 之后定位 修改就可以了。

但是,注意但是了啊!转折了啊!
但是现在xml文件的格式变化了 变为:

 
 
 
  aaa
 

 

   
  bbb
 


就是在以前的基础上改为 一个category里面还可以有 N 个 category, 所以这种情况 如果改某个特定的category的值的话 我就不会了。比如 把 id为 ca4的 category的值 改为 xxx, 我就不知道了。
我想还用 xpath 但不知道怎么用 
$xpath->query("/root/collection/在这我就不知道应该怎么写了/category[@id='"aaa"']"); 

像以前我知道collection下面一定是category而且只有一层,所以我可以很容易定位。现在我就不会了。请大家帮助我。谢谢。

------解决方案--------------------
/root/collection//category[@id='aaa']

这样.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn