×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: userc865b
Added: Aug 30, 2017 3:26 PM
Views: 2
Tags: js
XML to html with javascript
  1. <!DOCTYPE html> <html>  <head> <title>Verarbeitung von XML-Dateien mit Ajax</title> <meta charset="windows-1252"> <style type="text/css"> body {background-color:#F1EDDA; color:#A88314} div.ausg {text-align:center}  #ausg-02 {text-align:left; margin-left:40%} </style> <script type="text/javascript">  var xmldata = null;     xmldata = new XMLHttpRequest();  function xmlData() {      if (xmldata.readyState == 4) {          var inhalt = xmldata.responseXML;         var ifluss = inhalt.getElementsByTagName("Fluss").length;         var antwt1 = inhalt.getElementsByTagName("titel")[0].firstChild.nodeValue;          document.getElementById("ausg-01").innerHTML = antwt1;          for (var i = 0; i < ifluss; i++){              var antwt2 = inhalt.getElementsByTagName("Fluss")[i].getAttribute("Name");             var antwt3 = inhalt.getElementsByTagName("Fluss")[i].getAttribute("Laenge");              document.getElementById("ausg-02").innerHTML += "<li>" + antwt2 + " - " + antwt3 + "</li>";         }     } }  window.onload = function() {      xmldata.open("GET", "datei.xml", true);     xmldata.onreadystatechange = xmlData;     xmldata.send(null); }  </script> </head>  <body> <div class="ausg">  <h1>Verarbeitung von XML-Dateien</h1> <h2 id="ausg-01"></h2> <ul id="ausg-02"></ul> </div> </body> </html>