[thelist] xmlrequest & reading xml data
Alex Beston
alex at deltatraffic.co.uk
Thu Oct 13 23:56:03 CDT 2005
hi evolt
im having trouble reading in more than one tag in xml.
at the moment the following (see code below) works with a xml document
with one tag
<inset>some text</text>
(contents of photocollection-withdata.xml)
but if i have more say:
<photo><inset>some text</text><caption>new york</caption></photo>
it wont be able to find inset with the error "no properties".
var photoinfo =
xmlcontent.getElementsByTagName("inset").item(0).firstChild.data;
why is getElementsByTagName not able to read a document with more than
one xml tag?
i thought perhaps its something to do with the loadXMLDoc function.
thanks,
Alex
--
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
}
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
alert("XML data OK")
var xmlcontent = xmlhttp.responseXML;
var photoinfo =
xmlcontent.getElementsByTagName("inset").item(0).firstChild.data;
document.write(photoinfo);
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.statusText);
}
}
}
</script>
</head>
<body onload="loadXMLDoc('photocollection-withdata.xml')">
<span id="content"></span>
</p>
--
-------------------------------------------
Office: 01273 297927 / mobile: 07814 630621
-------------------------------------------
More information about the thelist
mailing list