I'm using   $ajax xml successfully for a google map project. The xml being delivered seems to have unusual tag structure but $ajax still parses it using following:

$.ajax({
    type: 'GET',
    url: 'somefile.xml',
    dataType: 'xml',
    error: function() {
        // do something
    },
   
    success: function(xml) {
        $(xml).find('record').each(function(){
           
            var id            = $(this).attr('id');           
            var street            = $(this).attr('street');                           
            var city         = $(this).attr('city');
            var state         = $(this).attr('c');
            var latitude         = $(this).attr('lat');
            var longitude     = $(this).attr('long');
            ///do something
        })
    });       
});
       
XML structure:
       
        <records>   
            <record
                     id="1"
                    street="155 W 47th St"
                    city="Chicago"
                    state="IL"
                    latitude="41.33333"
                    long="-87.555111"
                />
        </records>
 
Hope this helps


Ian Piper wrote:
Hi all,

This is my first posting to this group, so I hope you will treat me  
gently.

I am having a problem with a script that I am writing and I believe it  
is centered within a piece of jQuery code. I have some code like this  
(simplified slightly):

	$.get('news/testfeed.xml', function(data) {
	$('record', data).each(function() {
         var $link = $('<a></a>')
           .attr('href', $('link', this).text())
           .text($('name', this).text());
         var $headline = $('<h4></h4>').append($link);


         var $summary = $('<div></div>')
           .addClass('summary')
           .html($('description', this).text());

         $('<div></div>')
           .addClass('headline')
           .append($headline)
           .append($summary)
           .appendTo($container);
       });

I am using this to read the <title> and <description> elements of an  
xml file which is the response from a RESTful request. I have put a  
simplified version of the xml file below (just one record, and removed  
the lom:classification stuff).

My problem, in a nutshell, is that the script works and displays data  
when I look at it in Safari or Firefox 2.0 (Mac). However, when I look  
at the same script running in Firefox 3 (Mac OS X or Windows) or IE7  
then nothing seems to be returned at all. I tried replacing the  
complex xml with a simple xml file like this:

==== simple xml ====
<?xml version="1.0" encoding="UTF-8"?>
<records>
     <record>
         <title>
             Title 1
         </title>
         <description>Description 1</description>
         <teaser>Teaser 1</teaser>
     </record>
</records>
==== simple xml ====

and this displays fine in all browsers. So my question is, why do the  
browsers have different behaviour with respect to reading complex  
elements out of xml data, and how do I get the data I need out of the  
complex xml data reliably in other browsers?

Thanks for any advice you may be able to offer.


Ian.
--

==== xml ====
<?xml version="1.0" encoding="UTF-8"?>
<zs:searchRetrieveResponse xmlns="http://www.mystuff.co.uk"
     xmlns:zs="http://www.loc.gov/zing/srw/" xmlns:diag="http://www.loc.gov/zing/srw/diagnostic/ 
"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.mystuff.co.uk schema/ 
content_node.xsd"
     xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/ 
"
     xmlns:lom="http://ltsc.ieee.org/xsd/LOM">
     <zs:version>1.1</zs:version>
     <zs:numberOfRecords>2319</zs:numberOfRecords>
     <zs:records>
         <zs:record>
             <zs:recordSchema>info:srw/schema/1/dc-v1.1</ 
zs:recordSchema>
             <zs:recordPacking>xml</zs:recordPacking>
             <zs:recordData>
                 <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-schema">
                     <lom:metaMetadata>
                         <lom:identifier>
                             <lom:catalog>NS</lom:catalog>
                             <lom:entry>15296</lom:entry>
                         </lom:identifier>
                     </lom:metaMetadata>
                     <teaser>Introduction to the secondary Frameworks  
section, including links to
                         background on the Frameworks as well as to  
the English, mathematics, science
                         and ICT sections. </teaser>
                     <name>xxx</name>
                     <notes>updated</notes>
                     <taggingConfidence>Medium</taggingConfidence>
                     <dc:title>Secondary - Home Page</dc:title>
                     <dc:description>Introduction to the secondary  
Frameworks section, including
                         links to background on the Frameworks as well  
as to the English,
                         mathematics, science and ICT sections. </ 
dc:description>
                     <dc:identifier>nsonline.org.uk~22760~15296</ 
dc:identifier>
                 </srw_dc:dc>
             </zs:recordData>
             <zs:recordIdentifier>15296</zs:recordIdentifier>
             <zs:recordPosition>1</zs:recordPosition>
         </zs:record>
		</zs:records>
</zs:searchRetrieveResponse>

==== xml ====

  

Reply via email to