Slim Framework simplexml_load_string parser error

Asked

Viewed 284 times

0

My application sends a string in XML format to the server.

        $(function() {

        var xml = "<?xml version='1.0' encoding='UTF-8'?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>";
        $.ajax({
            type: "post",
             data: { xml : xml},
             contentType: "application/xml; charset=UTF-8; charset=utf-8",
            dataType: "json",
            url: 'http://www.e-sms.com.br/api',
            success: function(data){
                console.log(data);
            },
            error: function (request){
                console.log(request);
            }
        });    
    });
    </script>

I get the following error.

"<br /><b>Warning</b>:  simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '&lt;' not found in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\Http\Request.php</b> on line <b>202</b><br /><br /><b>Warning</b>:  simplexml_load_string(): xml=%3C%3Fxml%20version%3D'1.0'%20encoding%3D'UTF-8'%3F%3E%20%3Cnote%3E%20%3Cto% in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\Http\Request.php</b> on line <b>202</b><br /><br /><b>Warning</b>:  simplexml_load_string(): ^ in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\Http\Request.php</b> on line <b>202</b><br /><br /><b>Fatal error</b>:  Uncaught exception 'RuntimeException' with message 'Unexpected data in output buffer. Maybe you have characters before an opening &lt;?php tag?' in C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php:552Stack trace:#0 C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php(344): Slim\App-&gt;finalize(Object(Slim\Http\Response))#1 C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php(298): Slim\App-&gt;process(Object(Slim\Http\Request), Object(Slim\Http\Response))#2 C:\xampp\htdocs\SITE\lib\api\api.php(71): Slim\App-&gt;run()#3 C:\xampp\htdocs\SITE\lib\api\api.php(40): lib\api\api-&gt;create_routes()#4 C:\xampp\htdocs\SITE\lib\api\api.php(33): lib\api\api-&gt;initialize()#5 C:\xampp\htdocs\SITE\lib\api\api.php(76): lib\api\api-&gt;__construct()#6 {main}  thrown in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php</b> on line <b>552</b><br />"

The Slim Framework has little documentation. I saw some solutions that indicate using an extension called Middleware. He does the parse. With the command Composer required slim/slim " 3.0" Middle is already installed. The app cannot find the Contenttype.php class. I believe that a feature like Composer already leaves the application with satisfied dependencies. Following that line of reasoning I don’t care about that.

My application can transfer data using

            contentType: "application/json; charset=UTF-8; charset=utf-8",
            contentType: "application/x-www-form-urlencoded; charset=UTF-8; charset=utf-8"

the problem is with XML. Any idea how I can fix this ?

1 answer

0

Dude, I see you’re passing the xml and the slim parser is not getting it. I imagine the problem is here:

data: { xml : xml}

It is unlikely that the above code sends an xml as a string. Just try:

data: {xml}

One way to check what is coming on the server is for you to return what was sent and see the answer in the browser tools.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.