Saturday, May 25, 2013

Parsing xm file with jquery

Parsing xml file without  tag name selector:

xml :

<?xml version="1.0" encoding="utf-8"?>
<portfolio>
  <web>
    <websitename class="nem">mypeopolls</websitename>
    <author class="nem">praveen</author>
  </web>
<portfolio>



jquery:

$(document).ready(function(){
        $.ajax({
            type: "GET",
            url: "xml_file.xml",
            dataType: "xml",
            success: function(xml){
        $(xml).find('web').each(function(){
        var tag1=$(this).find('.nem')[0].tagName;
        var tag1_text=$(this).find(tag1).text();    
alert(tag1_text);

        //var tag2=$(this).find('.nem')[1].tagName;
        //var tag2_text=$(this).find(tag2).text();
    
            });
        },
error: function() {
            alert("error...");
            }
        });
});