2012-03-27 6 views
2

Dieser Code funktionierte und als wir auf PHP 5.3.10 aktualisierten, hörte es auf zu arbeiten und fing an, einige wirklich merkwürdige Fehler zu werfen.Aktualisiert auf PHP 5.3.10 und simpleXMLelement ist defekt

Die ursprüngliche XML validiert auf w3c.org ohne Fehler, aber ich habe die Website aus Gründen der Kürze und Sicherheit speziell bearbeitet.

Die XML (der Kürze halber bearbeitet, aber Fehler in Zeile 1 hergestellt):

<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> 

Die PHP-Fehler von error_log:

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

Und falls jemand bei der Arbeit ist, ist die URL in der XML wahrscheinlich nsfw. – halfer

+0

Vielleicht versuchen Sie Beispiel 1 von http://www.php.net/manual/en/simplexml.examples-errors.php, um zu sehen, ob der XML-Parsing-Fehler beschreibender ist. – cOle2

Antwort

1

Von Ihren Fehlern glaube ich, dass Ihr Problem darin besteht, Ihre Namespaces nicht zu registrieren. Nämlich dein Standard-Namespace. Es gibt ein paar Möglichkeiten, das zu tun, es hängt nur davon ab, wie Sie die Daten verarbeiten.

XPATH:

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

Kinder():

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