java生产xml时如何指定xml的编码格式 下面是我生成xml文件的代码 while(rs.next()) { Element childElemen
1个回答
展开全部
//输出XML流
private void outputXML() throws DTreeException {
DOMSource domSource = new DOMSource (doc);
StreamResult streamResult = new StreamResult(this.out);
try {
TransformerFactory transformerFactory=TransformerFactory.newInstance();
Transformer transformer=transformerFactory.newTransformer();
Properties properties = transformer.getOutputProperties();
properties.setProperty(OutputKeys.ENCODING, "gb2312 ");
properties.setProperty(OutputKeys.VERSION, "1.0 ");
transformer.setOutputProperties(properties);
transformer.transform(domSource,streamResult);
}
catch (TransformerConfigurationException tce) {
tce.printStackTrace();
throw new DTreeException( "TransformerConfigure Exception: "+tce.getMessage());
}
catch (TransformerException te) {
te.printStackTrace ();
throw new DTreeException( "Transformer Exception: "+te.getMessage());
}
}
private void outputXML() throws DTreeException {
DOMSource domSource = new DOMSource (doc);
StreamResult streamResult = new StreamResult(this.out);
try {
TransformerFactory transformerFactory=TransformerFactory.newInstance();
Transformer transformer=transformerFactory.newTransformer();
Properties properties = transformer.getOutputProperties();
properties.setProperty(OutputKeys.ENCODING, "gb2312 ");
properties.setProperty(OutputKeys.VERSION, "1.0 ");
transformer.setOutputProperties(properties);
transformer.transform(domSource,streamResult);
}
catch (TransformerConfigurationException tce) {
tce.printStackTrace();
throw new DTreeException( "TransformerConfigure Exception: "+tce.getMessage());
}
catch (TransformerException te) {
te.printStackTrace ();
throw new DTreeException( "Transformer Exception: "+te.getMessage());
}
}
追问
还有没有其他的方法,不要改我的代码
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询