Parsing prototype’s responseXML in JavaScript

Here’s a quick code snippet to parse the responseXML using JavaScript.

I am printing the xml file using php, feel free to use your server side scripting language.

First make a quick Ajax.Request call to send the data to server file.

function AddItem() {

var input = ‘myinput=’+$F(‘myinput’);
var list = ‘ListID=’+$F(‘ListID’);
var user = ‘userID=’+$F(‘userID’);

var pars = input+’&’+user+’&’+list;

new Ajax.Request(

  onComplete: ShowData 
return false;


Now that we have sent the data to our server file, in the above case its GetItem.php

Print the xml file in the php side.

Collect the reponse from the server in the form of the responseXML.

Below is the code to parse the responseXML and picking it up in javascript DOM.

function ShowData(originalRequest) {
var xmlDoc = originalRequest.responseXML.documentElement;

var value = xmlDoc.getElementsByTagName(“ItemValue”)[0].childNodes[0].nodeValue;
var value1 = xmlDoc.getElementsByTagName(“ItemID”)[0].childNodes[0].nodeValue;

divID = ‘DIV’+value1;

var div = document.createElement(‘div’);
div.className =’ItemRow’; = divID;

var val = ‘”‘+value+'”‘;

var i = document.createElement(‘input’);
i[“onclick”] = new Function(“MarkDone(”);
var t = document.createTextNode(value);



new Effect.Highlight($(div));

This has worked perfectly for me, let me know if you run into issues with this code.



About srinix

I am Sridhar, a matured nut, on this planet with water, air and love ;)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: