Home  >  Article  >  Backend Development  >  用xpath表达式查询出xml文档中年纪小于24岁的学生

用xpath表达式查询出xml文档中年纪小于24岁的学生

WBOY
WBOYOriginal
2016-06-13 11:58:051021browse

用xpath表达式查询出xml文档中年龄小于24岁的学生


   
      28年龄>   
   学生>
   
      23年龄>   
   学生>
   
      22年龄>   
   学生>
学生列表>

请问根据题目的要求,xls文档我该怎么写?请各位不吝赐教
------解决方案--------------------

$s =<<< XML<br /><?xml version="1.0" encoding="utf-8\"?><br /><学生列表><br />   <学生 姓名="王芳"><br />      <年龄>28</年龄>   <br />   </学生><br />   <学生 姓名="张海"><br />      <年龄>23</年龄>   <br />   </学生><br />   <学生 姓名="赵刚"><br />      <年龄>22</年龄>   <br />   </学生><br /></学生列表><br />XML;<br />$xml = simplexml_load_string($s);<br />foreach($xml->xpath("//*[年龄<24]") as $node) {<br />  echo $node->attributes() . ":" . $node->$b . PHP_EOL;<br />}<br />
张海:23
赵刚:22

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
Previous article:php入门微懂得Next article:php入门微了解