Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > XML Code Examples

Build document from a dom

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
Build document from a dom package com.ack.xml.jdom; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.jdom.input.DOMBuilder; public class BuildDocumentFromADom { public static void main( String[] args ) { try { // configure the document builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware( true ); // get a builder to create a DOM document DocumentBuilder domBuilder = factory.newDocumentBuilder(); // parse the damned document org.w3c.dom.Document w3cDocument = domBuilder.parse( "drainpipe.xml" ); // create a JDOM DOM Builder DOMBuilder jdomBuilder = new DOMBuilder(); // create a JDOM Document from a w3c DOM org.jdom.Document jdomDocument = jdomBuilder.build( w3cDocument ); System.out.println( jdomDocument ); } catch( Exception e ) { e.printStackTrace(); } } }