Advertisement
eriobe

XML med jQuery (js)

Oct 30th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.  
  3.   $.ajax({
  4.     type: "GET",
  5.     url: "instrument.xml",
  6.     dataType: "xml",
  7.     success: function(xml){
  8.     $(xml).find('instrument').each(function(){
  9.       var namn = $(this).find('namn').text();
  10.       var typ = $(this).find('typ').text();
  11.      
  12.       $(this).find('strangar').each(function(){
  13.         var strang = $(this).find('strang').text();
  14.         var attribut = $(this).find('strang').attr;
  15.         id = "<br /> Strängar: ";
  16.         $(this).find('strang').each(function(index){   
  17.              
  18.              $.each(this.attributes, function() {
  19.        
  20.                  id += strang[index].toUpperCase() + " (" + this.name + " " + this.value +") ";
  21.                  
  22.              });
  23.         });
  24.        
  25.         $("<h3></h3>").html(namn).appendTo("#accordion");
  26.         $("<div></div>").html(typ + id).appendTo("#accordion");
  27.         $( "#accordion" ).accordion( "refresh" );
  28.       });
  29.    
  30.        
  31.     });
  32.    
  33.   },
  34.   error: function() {
  35.     alert("Det gick inte att skapa xml-filen");
  36.   }
  37.   });
  38.   $( "#accordion" ).accordion();
  39.  
  40.  
  41. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement