simon373
Programmer
- Oct 25, 2006
- 25
Hi,
I have a project where I need to retrieve data on animals from an XML file. The XML file might look like:
<?xml version="1.0"?>
<animals>
<cat>
<headertext>
Animal Facts - Cat
</headertext>
<descriptiontext>
A cat is a an intelligent animal.
</descriptiontext>
<photourl>
../images/cat.jpg
</photourl>
<gameurl>
../games/catgame.swf
</gameurl>
</cat>
</animals>
Obviously, there will be more animals within it.
I have loaded the XML data into my web page using the following javascript:
<script type="text/javascript">
var request = new XMLHttpRequest();
request.onreadystatechange = myStatusProc;
request.open( "GET", "data/animalinfo.xml", true );
request.send();
function myStatusProc()
{
if (request.readyState == 4)
{
if(request.status == 200)
{
var response = request.responseXML.documentElement;
}
}
}
So, lets say I open a the cat web page, how do I retrieve and display information from specific nodes within the cat element?
Is there an easier way of doing this, with JSON? I am familiar with PHP and know how I would do it using PHP, but I would like to improve my Javascript / XML knowledge!
Many thanks, Simon.
I have a project where I need to retrieve data on animals from an XML file. The XML file might look like:
<?xml version="1.0"?>
<animals>
<cat>
<headertext>
Animal Facts - Cat
</headertext>
<descriptiontext>
A cat is a an intelligent animal.
</descriptiontext>
<photourl>
../images/cat.jpg
</photourl>
<gameurl>
../games/catgame.swf
</gameurl>
</cat>
</animals>
Obviously, there will be more animals within it.
I have loaded the XML data into my web page using the following javascript:
<script type="text/javascript">
var request = new XMLHttpRequest();
request.onreadystatechange = myStatusProc;
request.open( "GET", "data/animalinfo.xml", true );
request.send();
function myStatusProc()
{
if (request.readyState == 4)
{
if(request.status == 200)
{
var response = request.responseXML.documentElement;
}
}
}
So, lets say I open a the cat web page, how do I retrieve and display information from specific nodes within the cat element?
Is there an easier way of doing this, with JSON? I am familiar with PHP and know how I would do it using PHP, but I would like to improve my Javascript / XML knowledge!
Many thanks, Simon.