Header javaperspective.com
JavaPerspective.com  >   Advanced Tutorials  >   3. XML processing with JDOM  >   3.14. JDOM and DOM integration

3.14. JDOM and DOM integration
Last updated: 25 January 2013.

This tutorial discusses JDOM and DOM integration.

Although they have similar names, JDOM and DOM are very different APIs. If you are working with JDOM on a project that shares XML documents with a DOM-based application, you are likely to convert JDOM documents to DOM documents and vice versa. The code below shows how to convert from JDOM to DOM:

import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.output.DOMOutputter;


public final class JDOMDemo {

   
public org.w3c.dom.Document jdomToDom(Document jdomDocument) throws JDOMException{
         
DOMOutputter outputter = new DOMOutputter();
         
return outputter.output(jdomDocument);
   
}

}

Here is the code that converts from DOM to JDOM:

import org.jdom2.Document;
import org.jdom2.input.DOMBuilder;


public final class JDOMDemo {

   
public Document domToJDom(org.w3c.dom.Document domDocument){
         
DOMBuilder builder = new DOMBuilder();
         
return builder.build(domDocument);
   
}

}


You are here :  JavaPerspective.com  >   Advanced Tutorials  >   3. XML processing with JDOM  >   3.14. JDOM and DOM integration
Next tutorial :  JavaPerspective.com  >   Advanced Tutorials  >   4. Miscellaneous Java features

Copyright © 2013 - 2016. JavaPerspective.com. All rights reserved.  ( Terms | Contact | About ) 
Java is a trademark of Oracle Corporation
Image 1 Image 2 Image 3 Image 4 Image 5 Image 6 Image 7