File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Merging XML documents with DOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Merging XML documents with DOM" Watch "Merging XML documents with DOM" New topic

Merging XML documents with DOM

Rikko Verrijzer
Ranch Hand

Joined: Jul 22, 2003
Posts: 34

I'm trying to modify a XML file with DOM. Basically what needs to be done is to translate all math inside a XML file from latex to mathML. Finding the math and translating it is to mathML no problem.

However the translation proces creates a new DOM XML tree. The problem I have is the integration of this new DOM tree into the old DOM tree.

I understood that the following lines of code should take care of this merging problem:

However this results in an error message like:
Exception in thread "main" org.apache.crimson.tree.DomEx: NOT_SUPPORTED_ERR: This DOM implementation does not support that node type.
at org.apache.crimson.tree.XmlDocument.importNode(
at translate.MathTransformation.process(

Now apparently I'm not allowed to inserted complete documents into another document, but any child node I try add instead of the root node generates to following error:

Exception in thread "main" org.apache.crimson.tree.DomEx: WRONG_DOCUMENT_ERR: That node doesn't belong in this document.
at org.apache.crimson.tree.ParentNode.checkDocument(
at org.apache.crimson.tree.ParentNode.appendChild(
at translate.MathTransformation.process(

I'm relatively new to DOM so this might be easy to solve.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
The first thing that occurs to me is a namespace conflict. If the node you want to import is in the MathML namespace but the original DOM does not know about the namespace you would get a conflict. (Just guessing - have not tried this.)
It may be that you will have to write a new document that knows all the namespaces involved.
I agree. Here's the link:
subject: Merging XML documents with DOM
It's not a secret anymore!