douzhong3038 2013-02-02 17:20
浏览 38
已采纳

XML - 获取特定属性

I am pretty new working with XML files and know that I probably have the terminology wrong for what I am trying to get.

Here's what I need, I am trying to get some information out of a returned XML file attribute but can't seem to make it work, specifically the value of ns1:href in each view element.

XML FILE

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:MediaGallery xmlns:ns1="http://www.w3.org/1999/xlink" xmlns:ns3="urn:media.services.chrome.com">
<view backgroundDescription="Transparent" shotCode="02" height="240" width="320" ns1:type="resource" ns1:href="http://media.carbook.com/MediaGallery/media/MjkyNzU4Xk1lZGlhIEdhbGxlcnk/cl7mfC4mn7ScF7PMs7UmWf4ugY-UxsNwkkEiGHPXygftzkCsGogn9A/2011CAD001a_320_02.png"/>
</ns3:MediaGallery>

Now, I have been able to loop through and get the attributes backgroundDescription, shotCode, height, width etc but the one I need is the ns1:href value.

How can I do this ? It's driving me nuts and I have not been able to find the answers online. Any help on this, plus a good resource to learn from would be greatly appreciated.

Thank you.

  • 写回答

1条回答 默认 最新

  • dpjj4763 2013-02-02 17:36
    关注

    bah! Still don't understand it but it seems that this worked.

    $xml =      new SimpleXMLElement($xml);
    foreach ($xml as $img)
    {
    $attr = $img->attributes('ns1', true);
    echo $attr['href'];
    echo "<p>";
    }
    

    Anyone have a good resource where I can learn more about XML files in general?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料