I'm having a difficult time parsing the following XML string.
I receive numerous errors when using SimpleXMLElement or simplexml_load_string.
I'm running PHP version 5.5.20.
<?xmlversion="1.0"encoding="utf-8"?>
<Responsetype="NAK">
<ResponseCode>231</ResponseCode>
<Description>Billingstate/provinceisrequired.</Description>
<Reference>VSTMUAS:060215CJM-12</Reference>
<TransactionID>1433251975406510979</TransactionID>
<ProcessingTime>0.590634</ProcessingTime>
</Response>
When I run the following code:
$xml = simplexml_load_string($myXMLData);
print_r($xml);
I get the following errors:
Warning: simplexml_load_string(): Entity: line 1: parser warning : xmlParsePITarget: invalid name prefix 'xml' in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): <?xmlversion="1.0"encoding="utf-8"?> in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): ^ in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): Entity: line 1: parser error : ParsePI: PI xmlversion space expected in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): <?xmlversion="1.0"encoding="utf-8"?> in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): ^ in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): Entity: line 2: parser error : error parsing attribute name in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): <Responsetype="NAK"> in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): ^ in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): Entity: line 2: parser error : attributes construct error in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): <Responsetype="NAK"> in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): ^ in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): Entity: line 2: parser error : Couldn't find end of Start Tag Responsetype line 2 in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): <Responsetype="NAK"> in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): ^ in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): Entity: line 2: parser error : Extra content at the end of the document in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): <Responsetype="NAK"> in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Warning: simplexml_load_string(): ^ in /home/pmotrad/public_html/content/CalvinsTesting.php on line 18
Please help me undertand what I am doing wrong.
Thanks,
Calvin
<Response>tag before my post and I did not notice any changes to the errors shown above, so I did not think that was the problem.SimpleXMLElementobject from a string. However the string is not good to get converted to an XML object, you should clean it and to do so read carefully the errors returned, they are quite straightforward