tags:

views:

54

answers:

1

I am trying to use Jquery to load the contents of an XML file and then format (html) the results. The only thing is that, I would like it to load only nodes in the XML file that contain a specific phrase. I have been unable to find instructions on this.

This phrase will be a variable so, I will have a master XML file with all values and different pages on the site will have different variables, thereby loading different items from the XML, on different pages.

Looking to use something similar to this method: http://think2loud.com/reading-xml-with-jquery/

It load the XML but, I cant get it look for specific text.

$(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "sites.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('site').each(function(){
                var id = $(this).attr('id');
                var title = $(this).find('title').text();
                var url = $(this).find('url').text();
                $('<div class="items" id="link_'+id+'"></div>').html('<a href="'+url+'">'+title+'</a>').appendTo('#page-wrap');
                $(this).find('desc').each(function(){
                    var brief = $(this).find('brief').text();
                    var long = $(this).find('long').text();
                    $('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
                    $('<div class="long"></div>').html(long).appendTo('#link_'+id);
                });
            });
        }
    });
});
+1  A: 

please paste the xml or its schema as well. Also just by looking at the code...isn't abit confusing to use a data type name as variable? I mean var long...

XGreen
@XGreen I didn't write the code above. Any jquery that will accomplish what I'm looking for will work :)Also because of the nature of the info, I cannot paste in the XML contents.
Batfan
well its hard not to see the xml. I can just guess. sometimes with some browsers you can not just run the page on local file system but it has to be browsed through localhost.this sometimes doesn't get data from xmlif you cant paste xml data just paste schema. that will do
XGreen