level 1
havsb
楼主
public class DOMConvert {
public static <T>void message(T s){
System.out.println(s);
}
public static void main(String[] args){
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File("jaxpTest1.xml"));
//output xml into a xml file
TransformerFactory tff = TransformerFactory.newInstance();
Transformer tf = tff.newTransformer();
tf.setOutputProperty("encoding", "gb2312"); //set encoding
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("converted.xml"));
tf.transform(source, result);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2012年12月15日 15点12分
1
public static <T>void message(T s){
System.out.println(s);
}
public static void main(String[] args){
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File("jaxpTest1.xml"));
//output xml into a xml file
TransformerFactory tff = TransformerFactory.newInstance();
Transformer tf = tff.newTransformer();
tf.setOutputProperty("encoding", "gb2312"); //set encoding
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("converted.xml"));
tf.transform(source, result);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}