PDA

View Full Version : DOM Problems


Dan
10-17-2002, 06:10 AM
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

jkd
10-17-2002, 08:56 PM
xmlDoc.getElementsByTagName("para").item(0).firstChild.nodeValue

:)

Dan
10-18-2002, 05:14 AM
Can you be more specific, please cos i had try with this & it does't work.:o

jkd
10-18-2002, 07:38 AM
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();

mpjbrennan
10-18-2002, 08:41 AM
firstChild.nodeValue may be picking up a whitespace node in your document.

patrick

Alex Vincent
10-19-2002, 02:58 AM
With that markup it shouldn't be...

Dan
10-21-2002, 03:00 AM
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.