...

View Full Version : How to get the childnodes of an element other than the root?



pjohalloran
05-06-2004, 05:44 PM
Hi,

Im trying to get the childnodes of a XML element. The element itself is a child of the root node so i cant use

"CHILDREN = ELNAME.documentElement.childnodes;"

How would i do this? ive tried the following:-

"CHILDREN = ELNAME.childnodes;"

Thanks for helping out a beginner...

sad69
05-06-2004, 09:14 PM
I'm pretty sure that works:


var children = el.childNodes;


Ensure that you've got the element and not merely the element's name (an element vs. a string), as from your code it looks a bit ambiguous to me.

As a beginner, I don't know if you've ever used an API, but here's a good one that I use:
http://krook.org/jsdom/Element.html

Hope that helps,
Sadiq.

pjohalloran
05-06-2004, 11:21 PM
Thanks for the help, that API especially is great.

Another problem...if you could please help

var firstNameNode = selectFilm_ALL.firstChild.nodeValue;

This line of code returns null to me and i know the contents of the XML file at that point are not null. They are strings.

Also i know im pointing at the right place. Its just that instead of passing a string, it passes back null.

(I might not get a chance to post a thanks cos i dont have internet access at the weekend but thanks in advance for any help at all you can give)

sad69
05-06-2004, 11:30 PM
As a reference, I used this:
http://www.mozilla.org/docs/dom/technote/tn-dom-table/

I'm assuming this is a textNode, so it's a bit different from regular nodes. So instead of using nodeValue, you should use the data field.


var firstNameNode = selectFilm_ALL.firstChild.data;


Let me know how that works out for you.

Good luck,
Sadiq.

pjohalloran
05-06-2004, 11:35 PM
Hi,

Thanks for your help!

I tried 'selectFilm_ALL.firstChild.data;' but now its outputting "undefined" instead of null..?

liorean
05-06-2004, 11:36 PM
Well, for Text nodes, the nodeValue and the data property should be the same. However, Element nodes have a nodeValue of null. You need to read out the Text node that is a child of the Element.
<http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1841493061>

BlueSuedeShoes
05-06-2004, 11:43 PM
Hi,

Im trying to get the childnodes of a XML element. The element itself is a child of the root node so i cant use

"CHILDREN = ELNAME.documentElement.childnodes;"

How would i do this? ive tried the following:-

"CHILDREN = ELNAME.childnodes;"

Thanks for helping out a beginner...

That would be an ecumenical matter

sad69
05-06-2004, 11:49 PM
That would be an ecumenical matter

What the heck does that mean?? I did some Google-ing and I came up with some definitions regarding the church..

Sadiq.

pjohalloran
05-06-2004, 11:54 PM
Ok thanks very much, my problems are sorted. :thumbsup:

Sadik -> did you ever watch Father Ted, an Irish sitcom, Please do yourself a favor and do, youll know what that means sometime in the middle of season 1. Classic stuff.

liorean
05-06-2004, 11:55 PM
Well, ecumenical has a lot of different meanings. In protestantic regioins of the world, it means cooperation between churches. In catholic regions it means the entire church is behind an action, or unified in an action. It can also mean cooperation between those two, or with churches of other religions.

However, we get back to religion. Ecumenical can also be used in the discussion of "religious" issues, such as emacs versus vim...

sad69
05-07-2004, 12:13 AM
Father Ted, eh? I've heard of that.. but I live in Canada, and even on our satellite, I've never seen it. I wonder if I can download it off of eDonkey or KazaaLite or something.. I'll check this evening. (I've been looking for something new to watch! Is it in English? How bad are the accents? Comparable to Trainspotting? I could understand that not toooo badly.. )

liorean: I think I understand your definitions (though I don't think I'd use it in a conversation, ever), but I don't think I see its use in this context.. wonder if BlueSuedeShoes can answer that.. or maybe it's an inside joke among Father Ted fans?

Anyway, doesn't matter.. glad it worked out for you pjohalloran! Happy DOMing!

Sadiq.

pjohalloran
05-07-2004, 12:18 PM
Yeah definetly get it, its the best comedy of all time in my opinion but you might have to be irish to really get all the jokes but youll enjoy it anyway...

pjohalloran
05-07-2004, 12:29 PM
Yeah definetly get it, its the best comedy of all time in my opinion but you might have to be irish to really get all the jokes but youll enjoy it anyway...


"Dougal: God, Ted. D'you remember that feller who was so good at fashion they had to shoot him?"

BlueSuedeShoes
05-07-2004, 03:19 PM
wonder if BlueSuedeShoes can answer that.. or maybe it's an inside joke among Father Ted fans?
Sadiq.

That would be an ecumenical matter



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum