Response with special characters in xml

1

I am trying to make a request get to a web service using the module $http of angularjs , my code is as follows, (it is inside a factory):

 getCurrentPositionByClientName: function(){
     var deferred = $q.defer();
     console.log("getbyclientename");

     $http({ 
         method: 'GET',
         url: 'http://url-webservice.com/etc/etc',
         headers: { 
           'Content-Type': "application/xml"
         } 
    }).then(function(result){
       deferred.resolve(result);
    }, function(error){
       deferred.reject(error);
    });

    return deferred.promise;
}

So far so good, it makes the connection and the request well, the problem I have is that the response is returning to me in xml format in theory, but with special characters like the following:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.tempuri.org/">
&lt;NewDataSet&gt;
  &lt;Table&gt;
    &lt;ItemName&gt;108&lt;/ItemName&gt;
    &lt;ItemID&gt;37&lt;/ItemID&gt;
    &lt;IMEI&gt;207728640&lt;/IMEI&gt;
    &lt;ActualDate&gt;2017-08-02T15:44:09-06:00&lt;/ActualDate&gt;
    &lt;Lat&gt;24.055410999999999&lt;/Lat&gt;
    &lt;Lon&gt;-110.288417000000000&lt;/Lon&gt;
    &lt;Direction&gt;0.00&lt;/Direction&gt;
    &lt;Speed&gt;0.0240&lt;/Speed&gt;
    &lt;Cause /&gt;
    &lt;TriggerValue /&gt;
    &lt;EntityType&gt;VEHICLE&lt;/EntityType&gt;
    &lt;IgnitionStatus&gt;1&lt;/IgnitionStatus&gt;
  &lt;/Table&gt;
  &lt;Table&gt;
    &lt;ItemName&gt;113&lt;/ItemName&gt;
    &lt;ItemID&gt;39&lt;/ItemID&gt;
    &lt;IMEI&gt;207224564&lt;/IMEI&gt;
    &lt;ActualDate&gt;2017-08-02T15:47:58-06:00&lt;/ActualDate&gt;
    &lt;Lat&gt;24.157910999999999&lt;/Lat&gt;
    &lt;Lon&gt;-110.312152000000000&lt;/Lon&gt;
    &lt;Direction&gt;128.00&lt;/Direction&gt;
    &lt;Speed&gt;10.6840&lt;/Speed&gt;
    &lt;Cause /&gt;
    &lt;TriggerValue /&gt;
    &lt;EntityType&gt;VEHICLE&lt;/EntityType&gt;
    &lt;IgnitionStatus&gt;2&lt;/IgnitionStatus&gt;
  &lt;/Table&gt;
&lt;/NewDataSet&gt;
</string>

My question is: How can I show instead of showing the special characters the < and > correctly? or is it necessary to make a conversion or is there a problem with my Content-type when making the request?

    
asked by José Gregorio Calderón 02.08.2017 в 20:36
source

1 answer

1

Well I did not find problems in content-type so, what I proceeded to do was replace the special characters once the response will arrive, using the replace method a stored procedure and the character that I wanted it to add. The code stayed as follows:

var xml = data.data;

xml = xml.replace(/(&lt;)/g, "<");
xml = xml.replace(/(&gt;)/g, ">");

console.log(xml);

and the console is as follows:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.tempuri.org/">
<NewDataSet>
  <Table>
    <ItemName>108</ItemName>
    <ItemID>37</ItemID>
    <IMEI>207728640</IMEI>
    <ActualDate>2017-08-02T19:28:22-06:00</ActualDate>
    <Lat>24.046662000000001</Lat>
    <Lon>-110.299024000000000</Lon>
    <Direction>0.00</Direction>
    <Speed>0.0280</Speed>
    <Cause />
    <TriggerValue />
    <EntityType>VEHICLE</EntityType>
    <IgnitionStatus>1</IgnitionStatus>
  </Table>
  <Table>
    <ItemName>113</ItemName>
    <ItemID>39</ItemID>
    <IMEI>207224564</IMEI>
    <ActualDate>2017-08-02T19:30:28-06:00</ActualDate>
    <Lat>24.102436999999998</Lat>
    <Lon>-110.312169999999990</Lon>
    <Direction>189.00</Direction>
    <Speed>34.0030</Speed>
    <Cause />
    <TriggerValue />
    <EntityType>VEHICLE</EntityType>
    <IgnitionStatus>2</IgnitionStatus>
  </Table>
</NewDataSet>
</string>

And ready.

    
answered by 02.08.2017 в 21:35