[jdom-interest] JDom 2 Dom, then Dom 2 JDom

Xuemin Guan xuemin at appresso.com
Thu Jan 17 10:58:42 PST 2002

I posted this problem a few months ago, but, it seems this
problem remains(BTW, I checked out the CVS today).

The problem: when convert between a JDom tree and a DOM
tree, if you convert the DOM tree which is converted from a JDom tree,
back to a JDom tree, exception happens. I played with a few XML files.
While some files are OK, some are not. It seems the one which has
an explicit namespace does not convert while. However, if you serialize
the DOM tree to a harddisk, then build a JDom tree from this file, then
everything is OK. I've attached a test program as the follows, and the
is the XML file which does not convert well.

Any thoughts?

import org.jdom.output.DOMOutputter;
import org.jdom.input.SAXBuilder;
import org.jdom.input.DOMBuilder;

import java.io.FileInputStream;

import org.w3c.dom.Document;

public class Jdom2DomTest {
 public Jdom2DomTest(String fileName) throws Exception {
  SAXBuilder saxBuilder = new SAXBuilder();
  DOMBuilder domBuilder = new DOMBuilder();

  org.jdom.Document jdomDoc = saxBuilder.build(new
  DOMOutputter domOutputter = new DOMOutputter();

  org.w3c.dom.Document w3cDoc = domOutputter.output(jdomDoc);

  jdomDoc = domBuilder.build(w3cDoc);
     w3cDoc = domOutputter.output(jdomDoc);

     jdomDoc = domBuilder.build(w3cDoc);


 public static void main(String[] args) throws Exception{
  if(args.length < 0) {
   System.out.println("Usage: java Jdom2DomTest filename");
  Jdom2DomTest tester = new Jdom2DomTest(args[0]);
Xuemin Guan
Software Engineer
Appresso SpA (www.appresso.com)
Tel:  +81-3-4412-7790(Direct)
Email: xuemin at appresso.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SAPRDI01.xml
Type: text/xml
Size: 39257 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20020118/9bb3599e/SAPRDI01.xml

More information about the jdom-interest mailing list