473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

processing XML with XMLHttpRequest

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 getElementsByTagName() 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
onreadystatechange function:

getjournalready = function(req)
{
alert(req.responseText); //this shows the document correctly
var xml = req.responseXML; //xml is not null (I've tested for this)
var i=0;
var html="<h2>Journal entries:</h2>";
while(i >= 0) //write html
{
title = xml.getElementsByTagName("title")[i];
username = xml.getElementsByTagName("username")[i];
ts = xml.getElementsByTagName("ts")[i];
text = xml.getElementsByTagName("text")[i];
if(title != null)
{ //it never makes it into this inner loop
html += "<h3>"+title.firstChild.data+"</h3>";
html += "<p>"+username.firstChild.data+",
"+ts.firstChild.data+"</p>";
html += "<hr />";
html += "<p>"+text.firstChild.data+"</p>";
i=i+1;
}
else{ i=-10; }
}
document.getElementById("content").innerHTML = 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.

Jul 23 '05 #1
2 1186
Ok, I think I found most of the problem. Inside one of the entries was
a '<' character. This seemed to be messing the parse up. It is quite
annoying that no errors or warnings showed up on the javascript console
of firefox. That would have made the problem much easier to locate.
Doubly annoying is that when I change the '<' to a '&lt' it also
doesn't parse. Would anyone know why this is happening? ok, thanks for
the help!

Jul 23 '05 #2

horndud...@gmail.com wrote:
Doubly annoying is that when I change the '<' to a '&lt' it also
doesn't parse. Would anyone know why this is happening? ok, thanks for the help!


It's supposed to be &lt; to escape a "<" less than character. You
forgot the semicolon.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sboles | last post by:
Hello, I am trying to process each node from XMLHttpRequest.responseXML and set the node's 'className' property based on the value of the 'class' attribute. I have written a recursive function...
10
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code....
3
by: sneill | last post by:
Hi, Can anyone point me in the right direction here? I'm loading an XML file which has a processing instruction (<xsl-stylesheet href="..."/>). I need a cross-browser solution which will...
5
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML...
10
by: shankwheat | last post by:
I'm experimenting with using a AJAX style "processing" icon. The process I'm running in the background with xmlHttp is intensive and takes a 5--10 secs to complete. Instead of my processing icon...
1
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do?...
6
by: Patrick Nolan | last post by:
I'm working on cross-platform portability of some javascript. My Macintosh testing platform is rather old. It has Safari 1.3.2 and Internet Explorer 5.2. I got Safari working, but now IE is...
1
by: sukil | last post by:
Hi, I have a requirement to generate a form based on various user selections at runtime. So, I am using XMLHttpRequest to call server side programs and passing them parameters that is then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.