使用 SimpleXML 从 URL 解析 XML [英] Parsing XML from URL using SimpleXML

查看:35
本文介绍了使用 SimpleXML 从 URL 解析 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在此 URL 上回显 XML 内容,但遇到了困难.这是我到目前为止所拥有的:

I'm trying to echo the XML content at this URL but I'm having difficulty. Here's what I have so far:

$url = "GetVideosServlet?queryId=1";

$xml = simplexml_load_file($url);

$value = (string) $xml->results->item[0]->id;

echo $value;

我不断收到错误,提示我试图获取非对象的属性.但我的印象是 simplexml_load_file 将我的 XML 字符串转换为对象??

I keep getting the error that I'm trying to get the property of a non-object. But I was under the impression simplexml_load_file converts my XML string INTO an object??

如果有人能告诉我如何回显任何内容,我将不胜感激.

If anyone could show me how to echo out any of the content, I'd be very grateful.

推荐答案

我想你只是错过了一个标签 query,试试:

I think you just miss a tag which is query, try:

$value = (string) $xml->query->results->item[0]->id;
echo $value;

这篇关于使用 SimpleXML 从 URL 解析 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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