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

Outputting Xml using Jdom

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
Outputting Xml using Jdom package com.ack.xml.jdom; import org.jdom.Document; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; public class OutputtingXmlUsingJdom { public static void main( String[] args ) { try { // use SAXBuilder to create DOM from numerous types of input SAXBuilder builder = new SAXBuilder(); builder.setExpandEntities( true ); Document doc = builder.build( "drainpipe.xml" ); // create and configure the XMLOutputter XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setTextTrim( true ); xmlOutputter.setIndent( 2 ); xmlOutputter.setNewlines( true ); // output the text xmlOutputter.output( doc, System.out ); } catch( Exception ioe ) { ioe.printStackTrace(); } } }