Loading
Xml Writer Reader Formatter

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Xml Writer Reader


Ans)

Write a DOM Document as Formatted XMLs file XMLWriter, SAXReader,
OutputFormat, Example.

This example shows us how to write a DOM Document as Formatted XMLs file.

In this Example we formatted the XML by using OutputFormat.
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XMLWriter;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;

public class XmlWriterReader {
    public static String CR = System.getProperty("line.separator");
    private XmlUtility() {
       
    }
   
    public static void writeDOM(Document doc, File file)
    throws IOException  {
        OutputStream out = new FileOutputStream(file);
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        outformat.setLineSeparator( CR );
        outformat.setNewLineAfterNTags(4);
        outformat.setNewlines(true);
  
      XMLWriter writer = new XMLWriter(out, outformat);
        writer.write(doc);
        writer.flush();
    }
   
    public static Document parseXml(File xmlFile){
        SAXReader reader = new SAXReader();
        Document document =null;
        try {
            document = reader.read (xmlFile);
        } catch (DocumentException e ){
        }
        return document;
    }
}



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Xml Writer Reader Formatter


Xml Writer Reader Formatter

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free