SimpleXML和名称空间 [英] SimpleXML and namespaces

查看:88
本文介绍了SimpleXML和名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码.

 <entry>
  <job:location>
   <job:id>24</job:id>
   <job:region>6</job:region>
  </job:location>
 </entry>

我对名称空间有疑问.如何在SimpleXML中读取job:region标签的内容.

I've problem with namespaces. How I can read content of job:region tag in SimpleXML.

推荐答案

尝试一下:

 <?php 
    $entry = simplexml_load_file('entry.xml');        
    printf("%s\n", $entry->children('job', true)->location->region);  
 ?> 

要查看上面的代码,请点击此处

To check the above code in action, click here

有关SimpleXml的更多信息,请参阅此文章

For more information about SimpleXml refer to this article

这篇关于SimpleXML和名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆