DOM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cathy

    #1

    DOM

    Hi,

    I am new to XML. I have a questions regarding DOM.

    <root>
    <demo demoatt="testat tr">This is PCDATA</domo>
    </root>

    The book I read presents 2 ways to get This is PCDATA
    (1) selectsinglenod e("/root/demo").nodevalu e
    (2) selectsinglenod e("/root/demo[0]").firstchild.n odevalue

    Why do I need to use firstchild in the 2nd method? Thanks.
  • Martin Honnen

    #2
    Re: DOM



    Cathy wrote:

    [color=blue]
    > I have a questions regarding DOM.
    >
    > <root>
    > <demo demoatt="testat tr">This is PCDATA</domo>
    > </root>
    >
    > The book I read presents 2 ways to get This is PCDATA
    > (1) selectsinglenod e("/root/demo").nodevalu e
    > (2) selectsinglenod e("/root/demo[0]").firstchild.n odevalue
    >
    > Why do I need to use firstchild in the 2nd method? Thanks.[/color]

    What you have above is XPath mixed with DOM, the XPath
    /root/demo
    selects <demo> element nodes that are children of the <root> element.
    The nodeValue of an element node is always null thus it doesn't help to
    access selectsinglenod e("/root/demo").nodevalu e as that yields null. I
    would suggest to use
    selectSingleNod e("/root/demo/text()").nodeva lue
    as that way the text node that is a child of the <demo> element node is
    selected and that is the node you are looking for.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    Working...