Jump to content

SImpleXML Warning


nkosinathi

Recommended Posts

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>&#x0; 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>&#x0;O&#x0; in /home/wwwsend/public_html/postSample_Reply3.php on line 70

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.