2012-03-27 110 views
2

這段代碼正在工作,當我們升級到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: &quot; or ' expected in /aa.php on line 125 
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: xmlns=\&quot;http://www.missingkids.com/amber/NCMECAmberAlert\&quot; 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=\&quot;http://www.missingkids.com/amber/NCMECAmberAlert\&quot; 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=\&quot;http://www.missingkids.com/amber/NCMECAmberAlert\&quot; 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=\&quot;http://www.missingkids.com/amber/NCMECAmberAlert\&quot; 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 
+1

而且,萬一有人在工作,在XML中的URL可能是NSFW。 – halfer 2012-03-27 20:19:45

+0

也許嘗試從http://www.php.net/manual/en/simplexml.examples-errors.php的示例1,看看xml解析錯誤是更多的描述。 – cOle2 2012-03-27 20:28:53

回答

1

從你的錯誤我相信你的問題是沒有註冊你的命名空間。即你的默認命名空間。有幾種方法可以解決這個問題,這取決於你如何處理數據。

XPATH:

$xml->registerXPathNamespace('default', 'http://www.hidden.com/AmberAlert'); 

兒():

$xml->children('http://www.hidden.com/AmberAlert');