Ok, I've been reading around a lot and haven't found an answer for
this. I'm using XMLHttpRequest to get an XML document from a java
servlet. When the response is processed I can view the text of the XML
document, but when I try and getElementsByTa gName() it is null. In fact
it seems that even firstChild is null. I'm just learning so go easy on
me.
Here is some example code. This is called by the XMLHttpRequest
onreadystatecha nge function:
getjournalready = function(req)
{
alert(req.respo nseText); //this shows the document correctly
var xml = req.responseXML ; //xml is not null (I've tested for this)
var i=0;
var html="<h2>Journ al entries:</h2>";
while(i >= 0) //write html
{
title = xml.getElements ByTagName("titl e")[i];
username = xml.getElements ByTagName("user name")[i];
ts = xml.getElements ByTagName("ts")[i];
text = xml.getElements ByTagName("text ")[i];
if(title != null)
{ //it never makes it into this inner loop
html += "<h3>"+title.fi rstChild.data+" </h3>";
html += "<p>"+username. firstChild.data +",
"+ts.firstChild .data+"</p>";
html += "<hr />";
html += "<p>"+text.firs tChild.data+"</p>";
i=i+1;
}
else{ i=-10; }
}
document.getEle mentById("conte nt").innerHTM L = html;
}
Here is an example xml document that is sent back from the servlet:
<?xml version="1.0" encoding="UTF-8"?>
<journal>
<entry>
<title>a title</title>
<username>joe </username>
<ts>2005-05-17 22:34:44.281</ts>
<text>This is a journal entry</text>
</entry>
</journal>
It's rudamentary right now, but I can't see what wrong just yet. I've
checked to make sure the the mime type is "text/xml". I'm at a loss
right now. Any help? Thanks.
this. I'm using XMLHttpRequest to get an XML document from a java
servlet. When the response is processed I can view the text of the XML
document, but when I try and getElementsByTa gName() it is null. In fact
it seems that even firstChild is null. I'm just learning so go easy on
me.
Here is some example code. This is called by the XMLHttpRequest
onreadystatecha nge function:
getjournalready = function(req)
{
alert(req.respo nseText); //this shows the document correctly
var xml = req.responseXML ; //xml is not null (I've tested for this)
var i=0;
var html="<h2>Journ al entries:</h2>";
while(i >= 0) //write html
{
title = xml.getElements ByTagName("titl e")[i];
username = xml.getElements ByTagName("user name")[i];
ts = xml.getElements ByTagName("ts")[i];
text = xml.getElements ByTagName("text ")[i];
if(title != null)
{ //it never makes it into this inner loop
html += "<h3>"+title.fi rstChild.data+" </h3>";
html += "<p>"+username. firstChild.data +",
"+ts.firstChild .data+"</p>";
html += "<hr />";
html += "<p>"+text.firs tChild.data+"</p>";
i=i+1;
}
else{ i=-10; }
}
document.getEle mentById("conte nt").innerHTM L = html;
}
Here is an example xml document that is sent back from the servlet:
<?xml version="1.0" encoding="UTF-8"?>
<journal>
<entry>
<title>a title</title>
<username>joe </username>
<ts>2005-05-17 22:34:44.281</ts>
<text>This is a journal entry</text>
</entry>
</journal>
It's rudamentary right now, but I can't see what wrong just yet. I've
checked to make sure the the mime type is "text/xml". I'm at a loss
right now. Any help? Thanks.
Comment