nkosinathi Posted December 8, 2010 Share Posted December 8, 2010 Thanks in advance for your help. I have the following code function traverseXMLNodes($xml) { $xml = stripslashes($xml); $xml =simplexml_load_string("<div>{$xml}</div>");//This the line that makes errors its line 70 echo 'Displaying contents of XML file...<br />'; print_r($xml); } Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : xmlParseCharRef: invalid xmlChar value 0 in /home/wwwsend/public_html/postSample_Reply3.php on line 70 (Where i have written This the line that makes errors) Warning: simplexml_load_string() [function.simplexml-load-string]: yid><eventid>60387073</eventid><numfrom>27826641429</numfrom><receiveddata>� in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : xmlParseCharRef: invalid xmlChar value 0 in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Warning: simplexml_load_string() [function.simplexml-load-string]: ventid>60387073</eventid><numfrom>27826641429</numfrom><receiveddata>�O� in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/ Share on other sites More sharing options...
salathe Posted December 8, 2010 Share Posted December 8, 2010 The XML contains an invalid character reference (x0;), which is not allowed in XML 1.0. Wherever you're getting the $xml string from needs to be fixed in one way or other (using CDATA perhaps if you need the NUL characters, or just by not including the illegal character referencess). Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1144334 Share on other sites More sharing options...
nkosinathi Posted December 9, 2010 Author Share Posted December 9, 2010 Thanks for trying to help everyone. I have saved the XML response (Using file save as and remove html) to my localhost and use SimpleXML library on local computer it works fine. The problem is when i get the response from other server and try to use SimpleXML on the returned XML response. Please i need this finished before end of year my Manager is breathing down my neck. Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1144850 Share on other sites More sharing options...
salathe Posted December 9, 2010 Share Posted December 9, 2010 Can you give a link to the XML on the "other server" (or an exact copy of it somewhere else)? What do you mean by "remove html" when you save it locally? Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1144875 Share on other sites More sharing options...
nkosinathi Posted December 9, 2010 Author Share Posted December 9, 2010 Thanks again for help The First URL is http://sendbulksms.co.za/withoutsimplexml.php This where the server response xml string is displayed (echo XML string) and no use of simplexml library function The second is http://sendbulksms.co.za/withsimplexmllibrary.php This where the simplexml library is used. I use the following code $xml = simplexml_load_string($xml); "remove html" meant instead of the I extracted the XML from the HTML. I then used simplexml_load_file(with the XML from response HTML) instead of simplexml_load_string on the localhost Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1144878 Share on other sites More sharing options...
salathe Posted December 9, 2010 Share Posted December 9, 2010 Thanks for providing the XML. It looks like the only problem is that the <receiveddata> elements contain (many) [/tt] which makes it not valid XML. What you do from here is entirely up to you, but if possible ask the XML provider to fix their XML. A simple [tt]str_replace() on the XML, to remove those invalid character references, is enough to make SimpleXML happily load the XML. Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1145075 Share on other sites More sharing options...
muzzs Posted December 9, 2010 Share Posted December 9, 2010 Hi nkosinathi, Thanks for posting your XML and question. If you go to http://www.xmlvalidation.com/ and paste in your XML, you will see that you have an invalid XML character �. I would pass this onto whoever is proving the XML and ask them to fix it. Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1145107 Share on other sites More sharing options...
nkosinathi Posted December 10, 2010 Author Share Posted December 10, 2010 @salathe I tried str_replace and it does not fix my problem. @muzzs I contacted them and waiting for their response (XML providers) Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1145246 Share on other sites More sharing options...
salathe Posted December 10, 2010 Share Posted December 10, 2010 @salathe I tried str_replace and it does not fix my problem. What exactly did you try? Yes, it does fix the problems I've mentioned unless either a) there's something else you're not telling us, or b) you didn't do the correct replacement. Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1145256 Share on other sites More sharing options...
nkosinathi Posted December 10, 2010 Author Share Posted December 10, 2010 Hi I tried this $xml = simplexml_load_string(str_replace(""," ",$xml)); and it worked thanks a lot (A Billion) guys. I am closing this. Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1145259 Share on other sites More sharing options...
salathe Posted December 10, 2010 Share Posted December 10, 2010 Great to see that you're happy. If you could press the green "mark solved" button down below these posts, others can see that the thread has been solved. Quote Link to comment https://forums.phpfreaks.com/topic/220999-simplexml-warning/#findComment-1145347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.