Bonjour,
Voilà j'ai un code qui permet d'afficher le contenu d'un fichier XML
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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/* FICHIER HTML * / <html> <body> <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","catalogue.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("CD"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> </body> </html>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <!--- CODE FICHIER catalogue.xml --> <?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited by XMLSpy® --> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> ....
Alors mon code s'exécute correctement sans problème, mais le problème que j'ai c'est que mon fichier catalogue existe dans un serveur et quand je remplace la ligne
par :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 xmlhttp.open("GET","catalogue.xml",false);
Il m'affiche rien !!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 xmlhttp.open("GET","http://www.w3schools.com/xml/cd_catalog.xml",false);
je pense que le problème est quand le programme essaie de lire mon fichier il trouve pas l'entête d'un fichier XML et puis il peut pas le lire !!
j'espère que vous m'avez compris, essayez de m'aider c'est vraiment urgent !!







Répondre avec citation
Partager