This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm using xerces to parse an XML document. Do you always have to check the node type to ensure that you are actually getting an element when you are traversing through the document? For example, if I have the xml <root> <numbers> </one> </two> </numbers> </root> and i am at the <root> and I do get ChildNodes, I get a nodelist consisting of numbers. If I immediately get the childnodes of that, then i always get #text returned instead of <one> or <two>. So i have to loop through the child nodes until i find an NODE.ELEMENT_NODE to be sure I have <one> or <two>. Is there anyway to ignore the whitespace so you can just use the api calls directly without having to loop through the nodelist all the time to get what you want? Hope that makes sense. Thanks Brian
Brian, To use Dhina's trick, you need to have a DTD, otherwise your parser cannot determine that your element has an "element only content model". Another alternative (only if you use a DOM Level 2 Core compliant DOM implementation) would be to use a Node iterator or a Tree walker with the help of the DocumentTraversal interface which is implemented through the Document object. Below is an example using the Node iterator:
Cheers, Beno�t [This message has been edited by Beno�t d'Oncieu (edited August 29, 2001).]