Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Newbie to XML - problem using xmlhttp

From: Tim Platt <tjp@------.--.-->
To: NULL
Date: 6/4/2007 6:39:00 AM

Until now I have not had any reason to learn about XML. I have spent
quite a few hours playing with examples and reading group discussions
like these - with a certain amount of success. However, I have a
specific task to accomplish, and so far I have fallen at the last
hurdle.

I want to display the following 'feed' from an external server on our
clients:

http://www.q3.hpi.co.uk/servlet/HpiGate1_0?forward=YES&efxid=0502863&password=testing&initials=tp&function=SEARCH&vrm=V110ABE&XML=YES&product=HPI11&deviceType=XM

I believe this generates data in an xml format. I assume that using
xmlhttp is the correct protocol to use (if I'm wrong please tell me).

I have copied the following code from http://www.w3schools.com:

<html>
<head>
<script type="text/javascript">
var xmlhttp

function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("msxml2.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=onResponse;
  xmlhttp.open("GET",url,true);
  xmlhttp.setRequestHeader("Content-Type","text/xml")
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
      return true;
    }
    else
    {
      alert("Problem retrieving XML data");
    }
  }
}

function onResponse()
{
  if(checkReadyState(xmlhttp))
  {
  document.getElementById('A1').innerHTML=xmlhttp.status;
  document.getElementById('A2').innerHTML=xmlhttp.statustext;
  document.getElementById('A3').innerHTML=xmlhttp.responsetext;
  var response = xmlhttp.responseXML.documentElement;
 
document.getElementById('A4').innerHTML=response.getElementsByTagName("Model")
[0].firstChild.data;
  }
}
</script>
</head>

<body onLoad="loadXMLDoc('http://www.q3.hpi.co.uk/servlet/HpiGate1_0?
forward=YES&efxid=0502863&password=testing&initials=tp&function=SEARCH&vrm=V110ABE&XML=YES&product=HPI11&deviceType=XM');">

<p><b>status:</b>
<span id="A1"></span>
</p>

<p><b>status text:</b>
<span id="A2"></span>
</p>

<p><b>response:</b>
<span id="A3"></span>
</p>

<p><b>response:</b>
<br><span id="A4"></span>
</p>

</body>
</html>

This appears to work fine for the status and reponsetext but I get an
error message for the responsexml - the error messages says the
elementbytagname is null.

However, if I manually save the xml file to disc and then replace the
server URL (in loadXMLDoc) with the name of the xml file it displays
the data i.e I don't get an error message.

What am I doing wrong here? I clearly don't really understand the use
of xmlhttp .

Any assistance would be gratefully received.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent