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

Select attribute in simplexml
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

Categories

HOME
gremlin
google-play
json.net
hp-exstream
objectgears
kalman-filter
bookshelf.js
adb
icloud
google-project-tango
disassembler
portia
spring-xd
izpack
ibm-odm
netflix
dosgi
saxon
ef-migrations
swiftlint
opencover
buildbot
apache-commons-io
chromebook
uninstall
log4js-node
libuv
junit5
binary-data
ioio
column-family
commit
http-referer
catalog
wpf-controls
serve
gulp-sourcemaps
g-code
dynamic-reports
jvm-languages
glew
ibpy
fakeiteasy
dotcover
hendrix
nativeapplication
snmptrapd
nsarray
azure-sdk
infix-notation
adxstudio-portals
multi-level
connect-by
angstrom-linux
prettytensor
make-install
fadeout
bluemix-app-scan
oauth2client
goose
separator
qtableview
wordml
fouc
0xdbe
service-accounts
operation
createprocessasuser
angular-local-storage
network-interface
google-style-guide
issuu
document-classification
typeof
valuechangelistener
rtmfp
srs
mbr
oam
flash-builder4.5
gwt-rpc
eventlistener
selected
tridion-worldserver
eclipse-templates
coredump
xmemcached
locationlistener
disclosure
iphone-web-app
sudzc
aquaticprime
ugc

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App