View Full Version : Getting text in xml element

09-01-2010, 02:34 AM
Ok, Simpler question. I'm trying to get the text in an xml element. Instead of getting just the text in the first child element I'm getting the text of all the children elements. How can I get it from just the first?

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

function xmlload(filexml)


myVar = xmlObj.childNodes(0).childNodes(19).firstChild.text;

document.getElementById("comment_t").innerText= myVar;

Old Pedant
09-01-2010, 03:14 AM
You *do* know this code will never work in any browser except MSIE, yes?

Anyway, what's the XML look like???

And in this line:

you haven't initialized myVar yet, so you should be getting nothing for that .value.

09-01-2010, 04:15 AM
Page I read forgot to mention that one apearently.. I do have the variable initialized, along with a few others. Just didn't think I need to indude all the initializations. In the wrong forum my next wuestion then.. need some way to read the xml that will work in the frame/browser that this is going to show in in Windows Presentation Foundation.

Old Pedant
09-01-2010, 06:32 AM
Two places in your code that depended on MSIE:

new ActiveXObject ==>> ActiveX is strictly a MicroSlop technology.

document.getElementById("comment_t").innerText ==>> innerText not available in other browsers.

Not hard to make it work in all browsers.

Don't see why this has anything (directly) to do with WPF. You do have to load the XML from a URL that is in the same domain as the page, of course. I assume you knew that?

09-01-2010, 09:26 AM
Yea I did. I've figured it out now. Sorry for taking so much of your time to no avail. :/

09-01-2010, 03:38 PM
You should check out YQL (Yahoo Query Language) if you feel like researching alternative methods.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum