• Post Reply 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

getting null from XML (AJAX)

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ranchers,

i have one servlet which returns some piece of xml.

response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache"); 0ut.write("<message><mes1>ashok</mes1><mes2>koti</mes2></message>");

The code i wrote in javascript is as follows

var message = req.responseXML.getElementsByTagName("message")[0];

alert(message.nodeName); <--ouput is : message -->
alert(message.nodeValue); <--output is : null -->
alert(message.hasChildNodes()); <--output is : true -->
alert(message.childNodes.length); <--output is : 2 -->

document.write(message.childNodes[0].nodeValue) <--output is : null -->

Can anyone help me , why i am getting null value when i print "message.childNodes[0].nodeValue"

Regards
Thanks in advance
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't post the same question to more than one forum. See here for an explanation of why I just deleted the other copy of this thread.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because you are not writing a well formatted XML document.

Eric
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About nodeValue
"If the object is a TextNode, the nodeValue property returns a string representing the text contained by the node. If the object is an element, the nodeValue returns null."

So message.nodeValue is null;

<mes1>ashok</mes1>------ "ashok" is a TextNode,but not "<mes1>ashok</mes1>"
------------------------------------------------------
please care the method to creat a xmlnode:
var createTexttitle=xmlDoc.createTextNode(titletext);
var createTitle=xmlDoc.createElement("title");
createTitle.appendChild(createTexttitle);
------------------------------------------------------

can you tell me what is the "message.childNodes[0]"?
sure ,It is not a TextNode just like "<mes1>ashok</mes1>"
you can write like this :"message.childNodes[0].firstChild.nodeValue"

[ August 13, 2006: Message edited by: snowwolf ]
[ August 14, 2006: Message edited by: Liu Zhixiang ]
 
achayya matta
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much sir.you saved my life
reply
    Bookmark Topic Watch Topic
  • New Topic