简单的 XML - 处理节点中的冒号 [英] Simple XML - Dealing With Colons In Nodes

查看:66
本文介绍了简单的 XML - 处理节点中的冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Flickr 读取 RSS 提要,但它有一些简单 XML 无法读取的节点(media:thumbnailflickr:profile 和等等).

I'm trying to read an RSS feed from Flickr but it has some nodes which are not readable by Simple XML (media:thumbnail, flickr:profile, and so on).

我该如何解决这个问题?当我查看 DOM 的文档时,我的头很痛.所以我想避免它,因为我不想学习.

How do I get round this? My head hurts when I look at the documentation for the DOM. So I'd like to avoid it as I don't want to learn.

顺便说一下,我正在尝试获取缩略图.

I'm trying to get the thumbnail by the way.

推荐答案

解决方案在 这篇不错的文章.您需要 children() 方法来访问包含命名空间的 XML 元素.此代码片段引用自文章:

The solution is explained in this nice article. You need the children() method for accessing XML elements which contain a namespace. This code snippet is quoted from the article:

$feed = simplexml_load_file('http://www.sitepoint.com/recent.rdf'); 
foreach ($feed->item as $item) { 
    $ns_dc = $item->children('http://purl.org/dc/elements/1.1/'); 
    echo $ns_dc->date; 
}

这篇关于简单的 XML - 处理节点中的冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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