Codage pour extraire les données d'un fichier XML par du HTML
Bonjour,
Je suis étudiante en Master 2. J'ai besoin de votre aide, nous avons un projet de groupe. Il s'agit d'extraire les données d'un fichier XML par du HTML. Dans le fichier XML nous avons plusieurs domaines de définitions, nous devons faire apparaître plusieurs boutons chacun ouvrant sur un domaine de définitions. Pour l'instant nous pouvons faire apparaître deux boutons cependant seul un tableau apparaît. Nous ne parvenons pas à trouver ce qu'il faudrait ajouter ou changer. Je vous remercie d'avance pour votre aide, qui nous serait très précieuse.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| <!DOCTYPE html>
<html>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Get Definitions legales</button>
<br><br>
<table id="definitionslegales"></table>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "FranceTerme.xml", true);
xhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Terme</th><th>Definition</th><th>Domaine</th></tr>";
var x = xmlDoc.getElementsByTagName("Article");
for (i = 0; i <x.length; i++) {
{
if ( x[i].getElementsByTagName("Dom")[0].childNodes[0].nodeValue == "Droit")
table += "<tr><td>" +
x[i].getElementsByTagName("Terme_balise")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("Definition")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("Dom")[0].childNodes[0].nodeValue +
"</td></tr>";
else { continue }
}
}
document.getElementById("definitionslegales").innerHTML = table;
}
</script>
</body>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Get Definitions Acoustiques</button>
<br><br>
<table id="definitionsAcoustiques"></table>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "FranceTerme.xml", true);
xhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Terme</th><th>Definition</th><th>Domaine</th></tr>";
var x = xmlDoc.getElementsByTagName("Article");
for (i = 0; i <x.length; i++) {
{
if ( x[i].getElementsByTagName("Dom")[0].childNodes[0].nodeValue == "Acoustique")
table += "<tr><td>" +
x[i].getElementsByTagName("Terme_balise")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("Definition")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("Dom")[0].childNodes[0].nodeValue +
"</td></tr>";
else { continue }
}
}
document.getElementById("definitionsAcoustiques").innerHTML = table;
}
</script>
</body>
</html> |