Hi,
I'm getting the following error when i try to get the next sibling of the current node in php:
Fatal error: Call to undefined method DOMElement::next_sibling() in C:\wamp\www\Ajax\getcd.php on line 1
does anyone know on what i'm doing wrong? thank you.
cd_catalog.xml
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
</CATALOG>
if the user selects Bob Dylan from the select box in the following getcd.html, i want the next sibling ie. COUNTRY: USA to display.
getcd.html
<script language="javascript" type="text/javascript">
function showCD(str){
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new activeXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById("txtHint").innerHTML=xmlhttp.responseText
}
xmlhttp.open("GET","getcd.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form action="">
<select name="cds" onchange="showCD(this.value)">
<option value="">Select a CD</option>
<option value="Bob Dylan">Bob Dylan</option>
<option value="Bonnie Tyler">Bonnie Tyler</option>
<option value="Dolly Parton">Dolly Parton</option>
</select>
</form>
<div id="txtHint"><b>CD info will be listed here</b></div>
</body>
</html>
getcd.php
<?php
$q=$_GET['q'];
$xmlDoc=new DOMDocument();
$xmlDoc->load("cd_catalog.xml");
$x=$xmlDoc->getElementsByTagName('ARTIST');
for($i=0;$i<=$x->length-1;$i++)
{
//process only element nodes
if ($x->item($i)->nodeType==1)
{
if ($x->item($i)->childNodes->item(0)->nodeValue==$q)
{ echo $x->item($i)->next_sibling(0)->nodeName.":";
echo $x->item($i)->next_sibling(0)->item(0)->nodeValue;
}
}
}
?>