SimpleXMLElement错误,但XML有效 [英] SimpleXMLElement error but xml is valid

查看:16
本文介绍了SimpleXMLElement错误,但XML有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错误:

[01-Sep-2011 08:15:01]php警告:SimpleXMLElement::__Construction()[<;a h ref=‘simplexmlelement.--construct’>simplexmlelement.--construct]:../DOMAIN/Feed-yself-tips.php:1:解析器错误:需要开始标记,在/HOME/DOMAIN/PUBLIC_html/mergedrss.php第135行中找不到‘<;’

[01-Sep-2011 08:15:01]php警告:SimpleXMLElement::__Construction()[<;a h ref=‘simplexmlelement.--construct’>simplexmlelement.--construct]:1f45 in/HOME/DOMAIN/PUBLIC_html/mergedrss.php第135行

[01-Sep-2011 08:15:01]php警告:SimpleXMLElement::__Construction()[<;a h ref=‘simplexmlelement.--construct’>simplexmlelement.--construct]:^in/home/domain/public_html/mergedrss.php在第135行

[01-Sep-2011 08:15:01]php致命错误:在/home/domain/public_html/mergedrss.php:135

中未捕获异常‘异常’,消息为‘字符串无法被解析为xml’ 堆栈跟踪: #0 /home/domain/public_html/mergedrss.php(135): SimpleXMLElement->__construct('.../domain...', 0, true) #1 /home/domain/public_html/mergedrss.php(57): MergedRSS->__fetch_rss_from_url('.../domain...') #2 /home/domain/public_html/feed.php(21): MergedRSS->export(false, true, 15) #3 {main} thrown in /home/domain/public_html/mergedrss.php on line 135

推荐答案

如果您确定xml格式正确,则导致此错误的两种最常见情况如下。

A)您为implexml元素提供的是文件名,而不是字符串。

// For files/urls use the following.
// See: http://www.php.net/manual/en/function.simplexml-load-file.php
$xml = simplexml_load_file('example.xml');

// For xml strings use the following.
// See: http://www.php.net/manual/en/function.simplexml-load-file.php
$xml = simplexml_load_string($exmpleString);
B)另一个常见问题是,您试图访问一个安全的站点(https://)和您的php副本在php.ini中没有启用openssl扩展。如果此问题适用于您,请向Google寻求帮助,因为解决方案会因您使用的是Linux服务器还是Windows服务器而有所不同。

如果没有您提供的更多信息(如源XML和代码),我将尽我所能。

祝你好运:)

这篇关于SimpleXMLElement错误,但XML有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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