2013-02-02 17:20
浏览 37

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 version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:MediaGallery xmlns:ns1="" xmlns:ns3="">
<view backgroundDescription="Transparent" shotCode="02" height="240" width="320" ns1:type="resource" ns1:href=""/>

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?

    解决 无用
    打赏 举报

相关推荐 更多相似问题