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);
}
}
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);
}
}
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
Next tutorial : JavaPerspective.com > Advanced Tutorials > 4. Miscellaneous Java features