DOM

Cathy

Usenet Archive
Joined
Nov 20, 2000
Messages
29
Reaction score
0
Hi,

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

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

The book I read presents 2 ways to get This is PCDATA
(1) selectsinglenode("/root/demo").nodevalue
(2) selectsinglenode("/root/demo[0]").firstchild.nodevalue

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

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Cathy wrote:

I have a questions regarding DOM.

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

The book I read presents 2 ways to get This is PCDATA
(1) selectsinglenode("/root/demo").nodevalue
(2) selectsinglenode("/root/demo[0]").firstchild.nodevalue

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

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 selectsinglenode("/root/demo").nodevalue as that yields null. I would suggest to use selectSingleNode("/root/demo/text").nodevalue 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top