Võ Văn Hải's blog

Chỉ có một điều tuyệt đối đó là mọi thứ đều tương đối…

Convert SAX to JDOM

Chuyển SAX thành DOM.


package convert;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import org.jdom.Document;

import org.jdom.JDOMException;

import org.jdom.input.SAXBuilder;

import org.jdom.output.XMLOutputter;

public class SAX2JDOM {

File file;

public SAX2JDOM(File file) {

this.file = file;

}

public Document convert() throws JDOMException, IOException {

SAXBuilder builder = new SAXBuilder();

Document doc = builder.build(new FileInputStream(file));

return doc;

}

public static void main(String[] args){
try{

String xmlFile="xmlfiles/books.xml" ;

File file = new File(xmlFile);

SAX2JDOM tester = new SAX2JDOM(file);

Document doc = tester.convert();

XMLOutputter outputter = new XMLOutputter();

outputter.output(doc,System.out);

}catch (Exception e) {

e.printStackTrace();

}

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: