XML : XML parsing with filtering

My XML file looks like this -

   <?xml version="1.0" encoding="UTF-8"?>      <prj:Flow xmlns:prj="url1" xmlns:com="url2" xmlns:ns2="url3" xmlns:con="url4" xmlns:ns0="url5" xmlns:ns1="url6" xmlns:ns3="url7">      <prj:str>      <prj:layout comp="abcd">        <prj:prop>           <prj:property name="Hardik" value="5000"/>        </prj:prop>      <prj:look>        <prj:lite name="bajaj">        <prj:lite name="honda">      </prj:look>      </prj:layout>  <prj:layout comp="efgh">        <prj:prop>           <prj:property name="Vipul" value="6000"/>        </prj:prop>      <prj:look>        <prj:lite name="yamaha">        <prj:lite name="honda">      </prj:look>      </prj:layout>      </prj:str>      </prj:Flow>    

I need to parse this XML such that I can retrieve the children of based on the comp value i.e if comp="abcd" then I should be displaying bajaj and honda in my html table. Today my parser is showing all the attributes irrespective of the comp value being used to filter. Any help is highly appreciated.

My Parser -

  $.ajax({      type: "GET",      url: 'sample.xml',      dataType: "xml",      success: function(xml) {         var compname = $(xml).find("prj\\:layout,layout").attr('comp');         if(compname == "abcd") {            $(xml).find("prj\\:look, look").each(function() {              var $entry = $(this);              var pic = $entry.find("prj\\:lite,lite").each(function() {                var name = $(this).attr('name');                $('<tr></tr>').html('<td>' + name + '</td>').appendTo('#listnames');          })        })      }  }      })    

No comments:

Post a Comment