xpath finds the value of xml nodes and node attributes

WBOY
Release: 2016-07-25 09:08:39
Original
1747 people have browsed it
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');
复制代码


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!