simplexml


Upgraded to php 5.3.10 and simpleXMLelement is broken


This code was working and when we upgraded to php 5.3.10 it stopped working and started throwing some really odd errors.
The original XML validates on w3c.org without errors however I've edited out the site specific for brevity and security.
The XML (edited for brevity but error is produced on line 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>
The php errors from error_log:
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
Try turning Off magic_quotes or putting your XML content through stripslashes before passing to SimpleXML.
From your errors I believe your problem is in not registering your namespaces. Namely your default namespace. There are a few ways of going about it, it just depends on how you are processing the data.
XPATH:
$xml->registerXPathNamespace('default', 'http://www.hidden.com/AmberAlert');
children():
$xml->children('http://www.hidden.com/AmberAlert');

Related Links

Save formatted xml
SimpleXML (Zend_Config_Xml actually) and foreach : which tag am I iterating?
simplexml_load_file() error happening in only localhost/xampp
SimpleXml tar.gz
simplexml_load_file error in PHP 5.3
simplexml_load_file not a valid URI issue
Can't turn XML response into an simplexml object
Having trouble getting Fogbugz API response into a SimpleXML object
Upgraded to php 5.3.10 and simpleXMLelement is broken
Parsing RSS Feed with SimpleXML
php simplexml_load_file (script url) failed to open stream
PHP - SimpleXML not returning object
Having trouble processing XML with PHP SimpleXML
Simplexml How to access all element of the same node
simplexml_load_file failed to open stream Http request failed
Using XML node names with hyphens in PHP [duplicate]

Categories

HOME
ibm-bluemix
pdf
lodash
relay
react-router
malloc
baqend
wamp
slurm
maude-system
izpack
size
quartz-scheduler
seaborn
pythonanywhere
text-rendering
crystal-reports-2008
lldb
dbext
kryo
cx-freeze
tokenize
mustache.php
captiveportal
django-storage
kannel
internet-explorer-9
replaceall
atlassian-crucible
unboundid
socialengine
google-rich-snippets
http-get
column-family
catch-all
framemaker
uiswipegesturerecognizer
language-concepts
ghost4j
normal-distribution
picasso
hexo
swisscomdev
gesture
ansible-playbook
tasker
awt
email-templates
eclipse-scout
google-closure
isbn
arena-simulation
midl
reactive-cocoa-5
thin
smartcontracts
apache-fop
togetherjs
nstextview
jxcore
nodebb
knpmenubundle
qtwebview
titanium-android
topbeat
cubes
visual-c++-2008
url-pattern
passport-google-oauth
ctest
hexdump
bluemix-app-scan
livequery
goose
tform
revolution-r
xpath-1.0
natvis
wso2cloud
reactive-banana
pundit
composite
directoryservices
kineticjs
nsmutabledictionary
internet-connection
rdl
flask-cors
ember-charts
oam
jplaton
django-nonrel
android-screen-support
twrequest
errai
asyncfileupload
work-stealing
custom-backend
subscript
hamachi
gdlib
yslow
infrastructure
jquery-ui-droppable
mirah
thunderbird-lightning
swing-app-framework
premature-optimization
procedural-music
data-acquisition

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App