Hi,
I have been playing around a bit with the DOM samples in the xerces distribution.
In the DOMCount example, to mention one instance, there is code of the type:
int type = node.getNodeType();
switch (type) {
// print document
case Node.DOCUMENT_NODE: {
...
}


       // print element with attributes
       case Node.ELEMENT_NODE: {
       ...
       }

       ...
}

Of course, that works, but this is not really very nice code in a real-world application. Ideally, I would like to use a visitor pattern to use polymorphism to choose the action to be taken based on the nodes - but I can't see a way to do this.

Why? Because the element hierarchy is based on the Node interface of the DOM which does not provide the hooks to do such things. And although I can subclass the implementation classes used in the document, that does not really help, as they still all look like "Node" to the DOM.

Is there any way to do something more robust and maintainable, like for example a visitor, to parse a DOM and execute node-type specific functionality without reverting to a switch statement?

Thanks for any suggestion...

   PM
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.



Reply via email to