这段代码正在工作,当我们升级到PHP 5.3.10时,它停止工作,并开始抛出一些非常奇怪的错误。升级到PHP 5.3.10和simpleXMLelement被打破
最初的XML在w3c.org上验证没有错误,但是为了简洁和安全,我编辑了特定的站点。
的XML(编辑为简洁,但在第1行产生错误):
<AmberAlertDirective
xmlns="http://www.hidden.com/AmberAlert"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hidden.com/en_US/AmberAlert.xsd">
<Directive>New</Directive>
<AmberAlertId>9969</AmberAlertId>
<MessageTimestamp>2012-03-27T00:35:11</MessageTimestamp>
<AmberAlert>
<Target>
<State Code="OH">
</State>
</Target>
</AmberAlert>
</AmberAlertDirective>
从error_log中的PHP错误:
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 2: parser error : AttValue: " or ' expected in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: xmlns=\"http://www.missingkids.com/amber/NCMECAmberAlert\" in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 2: parser error : attributes construct error in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: xmlns=\"http://www.missingkids.com/amber/NCMECAmberAlert\" in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 2: parser error : Couldn't find end of Start Tag AmberAlertDirective line 1 in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: xmlns=\"http://www.missingkids.com/amber/NCMECAmberAlert\" in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 2: parser error : Extra content at the end of the document in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: xmlns=\"http://www.missingkids.com/amber/NCMECAmberAlert\" in /aa.php on line 125
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^in /aa.php on line 125
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /aa.php:125
Stack trace:
#0 /aa.php(125): SimpleXMLElement->__construct('<AmberAlertDire...')
#1 /AAServlet.php(64): processAmber('<AmberAlertDire...')
#2 {main}
thrown in /aa.php on line 125
而且,万一有人在工作,在XML中的URL可能是NSFW。 – halfer 2012-03-27 20:19:45
也许尝试从http://www.php.net/manual/en/simplexml.examples-errors.php的示例1,看看xml解析错误是更多的描述。 – cOle2 2012-03-27 20:28:53