Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Parsing XML String

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Guys,

I am having problem in parsing XML String in JavaScript. My XML String looks like this :

TABLE="<user>
<userid>101</userid>
<username>Sachin</username>
</user>"

This XML string is created in Servlet and sent using responseText. I am using DOM parser to parse TABLE, but cant.

code sample is:
----------------------
function importXML(txt)
{

if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);

}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4)
{
var x=xmlDoc.getElementsByTagName("user");

document.write(x[0].childNodes[0].nodeValue); //error : Object Required

alert(xmlDoc.getElementsByTagName("user"));
//not diplaying any thing
//var x=xmlDoc.getElementsByTagName("fname").childNodes[0].nodeValue;
//alert(x);
//createTable()
}
}
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.loadXML(txt);

}


function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {

var data=xmlhttp.responseText; //getting XML String :OK
alert(data); //displaying XML String :OK
importXML(data);

}
}
}


Tnak You
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question more than once.
 
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic