Ajax repose as reponseXML

I never had luck in getting responseXML from Ajax call. I have been following each and every post in this forum regrading the Ajax and I myself had partcipated in few. I never had/have issue in getting reposeText. It works perfect. But I really really want to get my result as an xml now. I know the basic thumb rule for reposeXML which says unless the xml is perfectly formatted, it will return blank.

I recently saw RoshiniG Gopals post and Merill's and other peoples valuable input on that topic . Merill also suggested the same for me long back.

I am positng my code. Please let me know where it is wrong. alerting responseXML gives me null and so the subsequent alert statements. In one of the forum someone suggested that ignore whether or not alert of responseXML gives null or not and simply call getElementsByTagName. I tried that also but no luck. alert('Value of XRows:'+xRows) gives me nothing

As I look for problems in your code, nothing jumps out at me. Please look at the "Hello World" AJAX example that appears as the last post in this linkTry coding it and running it. I'd be interested to know if you get a responseXML when you run this example. Also, which browser are you using? I tried this example on both IE V6, and Firefox.

Following are the observations that I noticed regarding reponseXML from Ajax call

1. When I added root element to the code that I shown above as per Anay Nayak's suggestion, it worked fine. So my final xml is <?xml version="1.0" ?> <entries> <entry>2006</entry> <entry>Please Pick One</entry> </entries>

2. Merill's example code shown at this link http://www.coderanch.com/t/53656/Struts/Ajax-struts-integration worked fine for me. But if you notice, he is not adding <?xml version="1.0" ?> . I tried adding/removing this to final xml response and does not make any difference. I thought it is mandatory to have <?xml version="1.0" ?> to get xml response, is this correct ?(???.....)

3. When I added second element to Merill's code like this out.write("<hello>hello world1</hello>"); out.write("<hello>hello world2</hello>"); His example stopped working and I started to get JavaScript error. This is because XML is not perfect as per the rule "only one top element is allowed in XML document"

I then changed like this to add root element out.write("<entries>"); out.write("<hello>hello world1</hello>"); out.write("<hello>hello world2</hello>"); out.write("</entries>"); It started to work fine now.

4. These are some Javascript observations. if you do this -> alert(req.responseXM)L you get -> [[object]] in javascript alert box if you do this -> alert('I have response: ' + req.responseXML) you get only -> "I have response:" in javascript alert box (I was expecting to see "I have response: [[object]]" ) Can't we alert an object by concatenating to a string (I never had experience doing this in before OR may be I am wrong ???.....)

Earlier, I have not proceeded to work with my issue since I was not getting anything by doing alert('I have response' + req.responseXML). I wanted to first get this message : "I have response: [[object]]" ) in javascript alert box and then wanted to proceed.