tags:

views:

76

answers:

2

So I'm using HTMLCleaner which returns a org.w3c.dom compatible DOM. Now, I want to insert my own subclassed Elements (which implement additional functionality outside the dom) into this dom tree. Is this possible?

If you use the Document.createElement(), you can't say that you want it to create your implementation of an element. Ideally I don't want my class to implement Element and Node have to manually do all the work that has already been done. I thought that I could subclass ElementImpl from Xerces and potentially add it to the DOM I have. However Xerces expects to be created into DOMs that implement CoreDocumentImpl etc.

It would be a pity, from an elegance point of view. If I had to use plain Element and manage to identify them by their attributes/names etc, as each one needs to point to particular positions in an index.

A: 

DOM is not the prettiest API to work with. If you want simplicity, use DOM4J : - Wrap the DOM document into a DOM4J document - Use DOM4J instead of DOM to build the existing document or wrap it in a DOM4J document

A: 

If possible, I'd recommend ditching Xerces for JAXB. It's a much friendlier API.

jasonnerothin