Bonjour,
mon besoin est proche de celui évoqué dans javascript XML mais pour ne pas polluer cette discussion, j'en crée une nouvelle. De même, j'ai besoin de lire un fichier XML. En voici un extrait :
Pour le lire, je me suis inspiré de ce tuto : http://pckult.developpez.com/tutorie...e-fichier-xml/
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="ISO-8859-1"?> <viewentries timestamp="20161211T112506,68Z" toplevelentries="165719"> <viewentry position="118099" unid="8EF292A9E34AD1F7C1257F3F000464BE" noteid="287D666" siblings="165719"> <entrydata columnnumber="0" name="GUID"> <text>SESA402250</text> </entrydata> <entrydata columnnumber="1" name="IsSEEmployee"> <text>No</text> </entrydata> </viewentry> </viewentries>
J'ai donc fait ce code :
mais page blanche
Code html+js : 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
34
35
36 <!DOCTYPE html> <html lang="fr"> <head> <meta charset="ISO-8859-1" /> <title></title> <style> </style> </head> <body> <div id="Div_XML"></div> <script> $(document).ready( function() { $.ajax( { type: "GET", url:"site2.xml", dataType: "xml", success: function(xml) { $(xml).find('viewentry').each( function() { var columnnumber = $(this).attr('columnnumber'); var entrydata = $(this).find('entrydata').text(); $('<div class="items" id="columnnumber_' + columnnumber + '"></div>').html(entrydata).appendTo('#Div_XML'); }); } }); } ); </script> </body> </html>
J'ai fait un second essai complètement différent. La source est cette fois http://www.w3schools.com/xml/met_ele...tattribute.asp.
xml :
Code xml : 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
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 <?xml version="1.0" encoding="UTF-8"?> -<bookstore> -<book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> -<book category="children"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> -<book category="web"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> -<book category="web" cover="paperback"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
Code html+js : 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 <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); function myFunction(xml) { var x, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName('book'); for (i = 0; i < x.length; i++) { txt += x[i].getAttribute('category') + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
mais de nouveau page blanche
Pourriez-vous me donner un code qui marche ?
Partager