ivanplenti
asked on
How can I read this xml in javascript?
hi, I am new with Javascript and XML, and I would like to know how can I read this XML file
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <properties xmlns="v1">
<comment>this is a comment</comment>
<entry key="your.address">main.st reet</entr y>
<entry key="your.name">Adele</ent ry>
</properties>
I need to read this xml and then show something like this using javascript
comment = this is a comment
your.address = main.street
your.name = Adele
I know that I can use
<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.X MLHTTP");
}
xmlhttp.open("GET","data.x ml",false) ;
xmlhttp.send();
xmlDoc=xmlhttp.responseXML ;
document.getElementById("c omment").i nnerHTML=
xmlDoc.getElementsByTagNam e("comment ")[0].chil dNodes[0]. nodeValue;
</script>
and I get the <comment> data "this is a comment" but how can I get the data from <entry key="your.address">main.st reet</entr y> for example to show something like this
comment = this is a comment
your.address = main.street
your.name = Adele
Thanks experts!
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <properties xmlns="v1">
<comment>this is a comment</comment>
<entry key="your.address">main.st
<entry key="your.name">Adele</ent
</properties>
I need to read this xml and then show something like this using javascript
comment = this is a comment
your.address = main.street
your.name = Adele
I know that I can use
<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.X
}
xmlhttp.open("GET","data.x
xmlhttp.send();
xmlDoc=xmlhttp.responseXML
document.getElementById("c
xmlDoc.getElementsByTagNam
</script>
and I get the <comment> data "this is a comment" but how can I get the data from <entry key="your.address">main.st
comment = this is a comment
your.address = main.street
your.name = Adele
Thanks experts!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help!
You're welcome
Open in new window