I understand that document.getRootElement returns the root but how do I get access to the two comment nodes?


Jeff Orris wrote:

To get to the root element of the document, you must first use
document.getDocumentElement().  Then you can traverse the children of the
root.


Richard Zschech <[EMAIL PROTECTED] To: [EMAIL PROTECTED] qrdata.com> cc: Subject: Document level comments getNextSibling() 04/29/02 08:58 AM Please respond to xerces-j-user





Hi,

Im having trouble treversing all the child nodes from the Document object.
Usually when treversing the child nodes from an Element for example I go:


Node node = element.getFirstChild(); while(node != null) { // do some processing

  node = node.getNextSibling();
}


But when I do this starting from a Document with comments and a root like:

<!-- comment 1 -->
<!-- comment 2 -->
<root/>

the nextSibling() method of the <!-- comment 1 --> node returns null.

The following method of iteraton also dosent work because
nodeList.getLength() returns 1.

NodeList nodeList = document.getChildNodes();
for(int i=0; i<nodeList.getLength(); i++) {
   // do some processing
}

Is this whats supposed to happen?

If I print the DOM tree with a identity JAXP transformer the whole tree
comes out so their obviously there Im just not accessing them correctly.
How does it treverse the documents children?

What am I doing wrong?

Thanks in advance,
From Richard.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to