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?

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog