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

Thread: DOM Problems

  1. #1
    Dan
    Dan is offline
    New Coder
    Join Date
    Oct 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DOM Problems

    Can i use the same tag name for DOM? I thought that if we want to use the same tag name,
    all we have to do is to change the .item(...).text?? Please help.

    This is what i type in xml:

    <page>
    <!--Unit 1.1 Page 1//-->
    <title>Definition of Communication</title>
    <para>Communication is a process involving the sorting.....</para>

    <para>Raymond Ross Speech Communication 6th edition</para>
    </page>




    This is what i type in html:

    para.innerText=
    xmlDoc.getElementsByTagName("para").item(0).text

    para.innerText=
    xmlDoc.getElementsByTagName("para").item(1).text

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    xmlDoc.getElementsByTagName("para").item(0).firstChild.nodeValue


  • #3
    Dan
    Dan is offline
    New Coder
    Join Date
    Oct 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you be more specific, please cos i had try with this & it does't work.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I am assuming you want to grab the text of the paragraphs.

    There is no such thing as a "text" property though.

    But because of the fact that your paragraphs only contain a text node, you can navigate to the text node, and read its nodeValue:

    refToParagraph.firstChild.nodeValue

    otherwise, you'd need to use a Range:

    var range = document.createRange();
    range.selectNode(refToParagraph);
    var theText = range.toString();
    range.detach();

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    firstChild.nodeValue may be picking up a whitespace node in your document.

    patrick

  • #6
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,459
    Thanks
    1
    Thanked 23 Times in 21 Posts
    With that markup it shouldn't be...
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #7
    Dan
    Dan is offline
    New Coder
    Join Date
    Oct 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey guys, think i solve the problem already by using javascript & the function call "xmlDoc.getElementsByTagName("to").item(0).text" . Thanks for all the help.


  •  

    Posting Permissions

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