views:

60

answers:

2

Hi All,

I have one problem , I want to get some data from XML file (if I can say that it is XML file), with jQuery:

This is my jQuery, it works with normal XML file :

$.ajax({
        type: "GET",
        url: "test.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('result').each(function(){
            var bid = $(this).find('bid').text();
            alert(bid);
            });
            }
        });

But this is the data:

   <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;
<?xml version="1.0" ?> 


<T_transmission> 
<result> 
<last>9.9200</last> 
<bid>9.9000</bid> 
<ask>9.9200</ask> 
<mid>9.9100</mid> 
</result> 

 </T_transmission>

</string>

Because it has "<string ...> it doesn't work ...

Can somebody suggest how to fix it or maybe there are another way to fix ...

Thanks a lot !!!!!!

A: 

You may have to update your version of jquery, or try to read the file like a regular file then use jquery to parse it.

alexy13
+2  A: 

If the xml format is totally outside your control you could hack it a bit like so. This worked for me in FireFox.

$.ajax({
  type: "GET",
  url: "test.xml",

  // change dataType to 'text' so that jquery doesn't try to parse xml
  dataType: "text",
  success: function(xml) {

    // just remove the declaration using replace()
    xml = xml.replace('<?xml version="1.0" ?>', '');

    $(xml).find('result').each(function(){
    var bid = $(this).find('bid').text();
    alert(bid);
    });
  }
});
jessegavin
You are really man !!!Thanks a lot !!!!!!!
Alexander Corotchi
My wife will be happy to hear that! You're welcome.
jessegavin