Q:

Why xml to json conversion is so slow?

I'm currently trying to improve the performances of my website but the XML2JSON lib I'm using is slowing the process and blocking the website.
Globaly I'm using AngularJS to get xml from a tird party php script :
$http.get('script.php', { params: { param1: $scope.param1, param2: $scope.param2 } }).
success(function(data, status) {
    $scope.results = x2js.xml_str2json(data);
});

The GET action takes around 30ms so I guess that the stuff blocking must be the x2js object.
http://code.google.com/p/x2js/
--
Edit : @Brian Genisio
The GET actually take about 30ms (maximum 1s in case of timeout) as seen on Firebug.
The string is kinda big (~3kb), and the particularity of X2JS is that it create a ginormous json object since it automatically create a simple field and an array for a XML entry :
<xml>
    <test>lol</test>
</xml>

will result in :
json: {
    test: lol,
    test_asArray: {
        lol
    }
}

Now yes, I do have control of the php scripts, but no, I can't get the data in json directly : The scripts I'm calling are calling a server, which don't have a JSON api.
--
Any idea why is it so slow ?

A:

Brian Genisio said: 

Can you return the data in JSON as well as XML to avoid client-side conversion ?

Aaaand that's actually better :

https://github.com/tamlyn/xml2json/blob/master/xml2json.php

You can define the xml elements you want to mandatory put as arrays :
// PHP
$array = xmlToArray($xml, array(
    'alwaysArray' => array('Element1', 'Element2'))
);
echo json_encode($arrayData);

