package ewanbao.mydomain.com;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import org.w3c.dom.Document;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSSerializer;
public class LoadAndStore {
public static void main(String[] args) {
try {
/* get a LS DOMImplementation */
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
/* load a xml into memory */
LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
LSInput input = impl.createLSInput();
input.setCharacterStream(new FileReader(new File(args[0])));
Document doc = parser.parse(input);
/* store a xml */
LSSerializer serializer = impl.createLSSerializer();
LSOutput output = impl.createLSOutput();
output.setCharacterStream(new FileWriter(new File(args[1])));
serializer.setNewLine("/r/n");
serializer.write(doc, output);
}
catch(Exception e) {
e.printStackTrace();
}
}
}