此代码正常运行,当我们升级到php 5.3.10时,它停止工作并开始抛出一些非常奇怪的错误。
原始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
答案 0 :(得分:2)
在传递给SimpleXML之前,请尝试turning Off magic_quotes或将您的XML内容放入stripslashes。
答案 1 :(得分:1)
从您的错误中我相信您的问题在于没有注册您的命名空间。即默认命名空间。有几种方法,它只取决于你如何处理数据。
XPATH:
$xml->registerXPathNamespace('default', 'http://www.hidden.com/AmberAlert');
儿童():
$xml->children('http://www.hidden.com/AmberAlert');