tags:

views:

278

answers:

3

I have an XML document which contains some invalid characters (é for example). Unfortunalty I cannot change the source XML file, and the file must be read through AJAX. How can I escape these characters client side?

Much thanks,

Steve

EDIT:

$.ajax({
     type: "GET",
     url: "http://foo.com",


     dataType: "xml",
     success: function(xml) {
      $(xml).find('images').each(function(){
       $(this).find('pic').each(function() {
        ...code...
       });

      });
     },
     error: function(XMLHttpRequest, textStatus, errorThrown){
      alert(textStatus);
     } 

    })
A: 

escape() and unescape() don't work for your architecture?

Filini
where would I add this in my posted example
Steven1350
nowhere, in your posted example. if the problem is during the jquery execution (parsing the results), then you really have to find out why it is failing (since é is totally valid in xml)
Filini
A: 

Probably you're looking for following xml processing instruction (PI):

<?xml version="1.0" encoding="ISO-8859-1"?>

EDIT 1: client-side solution:

Can you read that xml content as string? If yes, replace existing PI by that above and .loadXML()

EDIT 2: Consider this link Specifying the Data Type for AJAX Requests

Rubens Farias
A: 

I sovled this one my self by convincing the admins for properly format their XML files. Once they removed/fixed the special characters, the problem was solved

Steven1350