tags:

views:

38

answers:

2

I have been having tremendous trouble getting this to work. There is no reason (to my knowledge) that this shouldn't work.

var xpath = '/course/module[@id=\''+modId+'\']/child::*';
var getData = sxe(xmldoc, xpath);
var result = getData.iterateNext();

The function returns the xpath. Just looks cleaner. This works 100%.

while (results)
{
    var text = result.getElementsByTagName('title')[0].nodeValue;
    document.write(text); // returns null
}

For the example, I use document.write, it returns null, but in my actual script, it usually says childNodes or whatever method I'm trying to access the data (I thought this would help) it never returns it. It causes an error and breaks it. When I use alert(), I get the exact text I want, everything works perfectly!

What is happening?!

A: 

try

var text = result.getElementsByTagName('title')[0].text;  //concatenates the text of all descendant nodes

or

var text = result.getElementsByTagName('title')[0].firstChild.nodeValue;
pinkfloydx33
"Uncaught TypeError: Cannot read property 'text' of undefined," and "Uncaught TypeError: Cannot read property 'firstChild' of undefined." Every time I try to pass it to a variable to get the text's value, it becomes undefined. When using alert(), it works perfectly. This makes no sense...
Tarik
oh you know what, try removing the [0] and use the second option
pinkfloydx33