Baffled by a getElementsByTagName failing with no clues

I have two pages, one calls the other with a XMLHttpRequest.
The first page calls and then receives the XML text which appears to be well formed.

All is good until I hit the getElementsByTagName .
The page then abruptly stops with no clues as to why.
Please help.


User info will be listed here...

and the following page which produces the XML text without problem.

<?php $con = mysqli_connect(ID and password, etc); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

$root_element = “main_users”;
$xml .= “<$root_element>”;

//mysqli_select_db($con,“ajax_demo”);
$sql=“SELECT * FROM user ;”;

$result = mysqli_query($con,$sql);
$num = $result->num_rows;

if($num>0)
{
while($result_array = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$xml .= “”;

  //loop through each key,value pair in row
  foreach($result_array as $key => $value)
  {
     //$key holds the table column name
     $xml .= "<$key>";

     //embed the SQL data in a CDATA element to avoid XML entity issues
     $xml .= "<![CDATA[$value]]>";

     //and close the element
     $xml .= "</$key>";
  }

  $xml.="</users>";

}
}
mysqli_close($con);

//close the root element
$xml .= “</$root_element>”;

//send the xml header to the browser
header (“Content-Type:text/xml”);

//output the XML data
echo $xml;

?>

I found the problem. Now SOLVED!
I needed to parse the incoming XML text into an XML object as follows:

xmlDoc=loadXMLString(xmlhttp.responseText);

I added the following function to do this:

function loadXMLString(txt)
{
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,“text/xml”);
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=false;
xmlDoc.loadXML(txt);
}
return xmlDoc;
}

Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service