Masroor_Shah Masroor_Shah - 1 year ago 86
Ajax Question

AJAX DATA fetch from XML

I am trying to fetch data from xml but it gives me error do not where is my mistake as i am new here please suggest my PHP code is here

<!doctype html>
<meta charset="utf-8">
<title>AJAX PHP FILE</title>

$xmlDoc = new DOMDocument();

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) {


for ($i=0;$i<$cd->length;$i++) {
//Process only element nodes
if ($cd->item($i)->nodeType==1) {
echo("<b>" . $cd->item($i)->nodeName . ":</b> ");

and My XML file code is here

<?xml version="1.0" encoding="utf-8"?>
<TITLE>Empire Burlesque</TITLE>
<TITLE>Hide your heart</TITLE>
<TITLE>Greatest Hits</TITLE>
<TITLE>Still got the blues</TITLE>
<COMPANY>Virgin records</COMPANY>

error snap is here
enter image description here

Answer Source

There is a small mistake in your XML file, on the last line. It should be </CATALOG> and not <CD></CATALOG>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download