Home >Backend Development >PHP Tutorial >xpath finds the value of xml nodes and node attributes

xpath finds the value of xml nodes and node attributes

WBOY
WBOYOriginal
2016-07-25 09:08:391812browse
xpath查找xml节点和节点属性的值
  1. $xml = "
  2. world
  3. ";
  4. function get_data_from_xml($res_data,$node)
  5. {
  6. $xml = simplexml_load_string($res_data);
  7. $result = $xml->xpath($node);
  8. while(list( , $node) = each($result))
  9. {
  10. return $node;
  11. }
  12. }
  13. // 'hello world';
  14. echo get_data_from_xml($xml, '/node/title/@src[.]'), ' ' , get_data_from_xml($xml, '/node/title');
复制代码


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