Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to get the childnodes of an element other than the root?

    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...

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm pretty sure that works:
    Code:
     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.

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)
    Last edited by pjohalloran; 05-06-2004 at 10:31 PM.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Code:
    var firstNameNode = selectFilm_ALL.firstChild.data;
    Let me know how that works out for you.

    Good luck,
    Sadiq.

  • #5
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for your help!

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

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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-Le...#ID-1841493061>
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by pjohalloran
    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

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BlueSuedeShoes
    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.

  • #9
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thanks very much, my problems are sorted.

    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.

  • #10
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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...
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #11
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #13
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by pjohalloran
    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?"

  • #14
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sad69
    wonder if BlueSuedeShoes can answer that.. or maybe it's an inside joke among Father Ted fans?
    Sadiq.
    That would be an ecumenical matter
    Last edited by liorean; 05-07-2004 at 02:27 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •