Jump to content

[SOLVED] Posting a xml variable using simplexml_load_string


Recommended Posts

hi,

 

my application is to receive an xml posted by others,

for example:

 

$xml = "<?xml version='1.0' encoding='utf-8'?>

<address>

<street>Lot 11, Happy Street</street>

<state>Florida</state>

<country>USA</country>

</address>

";

 

 

 

$ch = curl_init("http://localhost/address/index.php");

curl_setopt($ch, CURLOPT_TIMEOUT, 20);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, array(

'xml' => $xml,

));

$response = curl_exec($ch);

curl_close($ch);

 

and i received it to process.

 

so i use

$xml_array = simplexml_load_string($_POST['xml']);

 

but the problem is it shows this errors:

Warning:  simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : String not started expecting ' or " in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]:              ^ in C:\AppSer\.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Malformed declaration expecting version in C:\AppSer\.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]:              ^ in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Blank needed here in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]:              ^ in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : parsing XML declaration: '?>' expected in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14

 

Warning:  simplexml_load_string() [function.simplexml-load-string]:              ^ in C:\AppSer\process.php on line 14

 

 

but then i tried to print_r($_POST['xml']) and i got this result:

<?xml version=\'1.0\' encoding=\'utf-8\'?>

<address>

<street>Lot 11, Happy Street</street>

<state>Florida</state>

<country>USA</country>

</address>

 

if seems like the server automatically convert the '1.0' into \'1.0\'

 

is this the cause that make the simplexml_load_string function work wrongly?

is there any way to solve this?

 

thanks alot

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.