This is better. The arrays are much more efficient, and I cut the code
by more than half. I know, I know JSON, I will get there, this is
teaching me way more though. I still would like to be able to
determine my level of nesting abstractly, and also getting out non-
standard attributes.
  function parseXml(xml) {
                $(xml).find('sites').each(function(){
                var PARENTarr = jQuery.makeArray($(this).find('>element'));
                var CHILDarr = jQuery.makeArray($(PARENTarr).find('>element'));
                        $.each(PARENTarr, function(i){
                                                var PfromA = $(this);
                                                var Pid = 
$(this).attr("label")+$(this).attr("id");
                                                var Cid = 
$(CHILDarr[i]).attr("label");
                                                $("div").append("<br/>"+Pid 
+"<br/>" + Cid +"<br/>");
                                                $(CHILDarr[i]).each(function(){
                                                        var CHILDattrs = 
jQuery.makeArray($(this).find('>element'));
                                                        
$(CHILDattrs).each(function(){
                                                                  var CHILDid = 
$(this).attr('label') +": "+ $(this).text();
                                                                  
$("div").append(CHILDid +"<br/>");
                                                          });
                                                });
                          });
                  });
        }
});

Reply via email to