Category Covered

Read two xml file using javascript

I have two xml file products.xml and categories.xml file. So i am going two make a tree that will show category and its related products.

 

$(document).ready(function(){
   $.get('xml/categories.xml',function(data){
    var _html="<ul>";
     $(data).find('Categories').each(function(key,value){
         _html+="<li>"+$(this).find('CategoryName').text();
		 catId = $(this).find("CategoryID").text();
		 asd = genTree(catId);
		 //console.log(asd);
		 _html+=genTree(catId);
        //console.log($(this).find("CategoryID").text());
          _html+="</li>";
      })
      _html+="</ul>";
      $("#tree").html(_html);
     
    });
	
    function genTree(_cat_id){
		
      	var ht="";
     	$.get('xml/products.xml',function(pdata){
			ht+="<ul>";
			$(pdata).find('Products').each(function(){
				if(_cat_id==$(this).find('CategoryID').text()){
					ht+="<li>"+$(this).find('ProductName').text()+"</li>";
					//console.log(ht);
				}
			})
			ht+="</ul>";
      	});
	  	console.log(ht);
     	return ht;
    }
    
  });