0

I have an xml webservice which I'm fetching using PrototypeJS. The xml has the correct content type and is well-formed, and looks like this:

<GetTokenResponse xmlns="http://tempuri.org/">
    <GetTokenResult>F655100D64F098F0AC33AFF414A4A0D5</GetTokenResult>
</GetTokenResponse>

The AJAX request is completing successfully, and I can access the GetTokenResult node in both IE and FF but can only get the text content of the node in FF. My code is below:

node = transport.responseXML.documentElement.getElementsByTagName('GetTokenResult')[0];
rawToken = (document.all) ? node.innerText : node.textContent;

I've tried innerText and innerHTML, as well as children[0] and a few other chance guesses but IE returns 'undefined' when I access rawToken.

Anyone able to lend a hand? Thanks, Adam

Rob W
  • 341,306
  • 83
  • 791
  • 678
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99

3 Answers3

1

Try accessing the node value as:

rawToken = node.firstChild.data;

This should work across all modern browsers, as well as IE.

Crescent Fresh
  • 115,249
  • 25
  • 154
  • 140
0

To get the text content, use firstChild.nodeValue

Neil
  • 1
-1

node = transport.responseXML - this is correct.

You end up with "node" as your XML in string format. Strip the rest. You need to turn the string into an XML document before you can manipulate it directly.

See: Convert String to XML Document in JavaScript

or see: http://www.discussweb.com/html-css-javascript-coding-techniques/3308-convert-ordinary-string-into-xml.html

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176