Lecture XML avec javacript
Bonjour � tous,
Je d�bute en javascript et j'ai rencontr� un probl�me plut�t inattendu.
Voil� plusieurs heures que je me casse la t�te pour afficher des donn�es d'un XML.
Lorsque je fais un alert sur le contenu d'un n�ud, rien de s'affiche sur firefox alors que "null" s'affiche sur IE.
J'ai simplifi� au max le code afin de ne pas vous faire perdre trop de temps.
Le fichier de base :
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
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>page</title>
<script type="text/javascript">
//<![CDATA[
function load() {
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
return;
}
xmlDoc.async=false;
xmlDoc.load("test.xml");
alert(xmlDoc.getElementsByTagName('photo')[0].firstChild.nodeValue);
}
//]]>
</script>
</head>
<body onload="load()">
<p> </p>
</body>
</html> |
Le fichier XML :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<?xml version="1.0"?>
<root>
<photo>
<idPhoto>1</idPhoto>
<lien>1.jpg</lien>
<latitude>49</latitude>
<longitude>3</longitude>
</photo>
<photo>
<idPhoto>2</idPhoto>
<lien>2.jpg</lien>
<latitude>48</latitude>
<longitude>4</longitude>
</photo>
</root> |
Vous pouvez tester �a ici : http://dekzi.free.fr/test/
En esp�rant que vous puissiez m'aider :oops:
Merci d'avance