Javascript XML Parsing

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

treydx

Thread Starter
Joined
Jan 4, 2006
Messages
112
I'm using AJAX to return an XML document to a webpage, but I can't seem to parse the resulting document. Everything I've tried says it's returning a null document. I can alert(xmlhttp.responseText) to see the physical document returned, and it looks good, I can even open the page in a browser window as xml (with the treeview & colored elements), so I'm almost positive that the resulting text is a valid XML document, but javascript doesn't want to parse it for me.

Here's my calling code from the source page:
Code:
function lookupold(frm)
{
...
	var xmlhttp = createXMLHTTPObject();
	var toURL = "../../includes/xmlhttp/PedometerData.asp?action=returnxml&empid=" + empid + "&dyear=" + dyear + "&dmonth=" + dmonth;

	xmlhttp.open("GET", toURL, false);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(null);

	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc = xmlhttp.responseXML;
	var nodes = xmlDoc.documentElement;
	alert(nodes); // returns "null"
}
if I alert xmlhttp.responseText, then I get
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xml>
<message>No results were found for 4127 on 2006-1-1</message>
</xml>
This resulting xml is correct.

xmlDoc.documentElement returns null
xmlDoc.documentElement.childNodes throws an error (obviously)
Am I trying to parse it wrongly? This code seemed to work on some of my other pages.

My PedometerData.asp page which returns the xml is as follows:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xml>
<%
action_ = Request("action")
empid   = Replace(Request("empid") &"", "'", "")
dyear   = Replace(Request("dyear") &"", "'", "")
dmonth  = Replace(Request("dmonth")&"", "'", "")
steps   = Replace(Request("steps") &"", ",", "")

'Action to execute SQL
Select Case action_

' Following cases are for returning data from the SPPedometerGet stored procedure
' SPPedomterGet @EmpId, @PedometerDate
Case "returnxml"
	Set cmdStoredProc = Server.CreateObject("ADODB.Command")

	With cmdStoredProc
		.ActiveConnection = conn
		.CommandText = "SPPedometerGet"
		.CommandType = adCmdStoredProc
		.Parameters.Append .CreateParameter("@EmpId",         adInteger, adParamInput, , empid)
		.Parameters.Append .CreateParameter("@PedometerDate", adDBDate , adParamInput, , dyear & "-" & dmonth & "-1")
	End With

	Set rs = cmdStoredProc.Execute 

	If Not rs.eof Then
		Do Until rs.eof %>
			<empid><%=rs("empid")%></empid>
			<date>
				<month><%=rs("dmonth")%></month>
				<year><%=rs("dyear")%></year>
			</date>
			<steps><%=rs("steps")%></steps>
		<% rs.movenext
		Loop
	Else
		%><message>No results were found for <%=empid%> on <%=dyear & "-" & dmonth & "-1"%></message><%
	End If

	rs.Close
	Set rs = Nothing
	conn.Close
	Set conn = Nothing
...
%>
</xml>
I omitted the rest of the CASE statements for code brevity, there are no syntax errors on that page.

Am I trying to open the wrong type of ActiveXObject? Why will responseText work, but responseXML won't?

Thanks for the help!
Trey
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top