public Document styleDocument( Document document, String stylesheet ) throws Exception { // load the transformer using JAXP TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer( new StreamSource( stylesheet ) ); // now lets style the given document DocumentSource source = new DocumentSource( document ); DocumentResult result = new DocumentResult(); transformer.transform( source, result ); // return the transformed document Document transformedDoc = result.getDocument(); return transformedDoc;}
解决方案 »
- 求助,有关ServletActionContext.getServletContext().getAttribute
- JSF:如何在页面获取dataTable某一列的值
- 使用preparedStatement.executeBatch(),如何捕获所有异常。
- 问个简单的list排序问题
- 《反模式》《敏捷开发》这两本本书怎么样?
- Caused by: java.sql.SQLException: 数据大小超出此类型的最大值的问题?
- hibernate 碰到数据库的触发器的时候出错了,急呀,帮看看
- 600分,关于Sun Message Queue的集群!
- jTable中增加了一个KeyPress事件后,最后一个列的数据就不能保存了?
- java.lang.Error: Unresolved compilation problems: 报错了
- J2EE开发工具
- 向大家请教个OPTION的问题
SAXReader reader = new SAXReader();
org.dom4j.Document document = reader.read("D:\\ha.xml");
OutputFormat of = new OutputFormat();
of.setEncoding("gb2312"); //改变编码方式
XMLWriter writer = new XMLWriter(new FileWriter "d:\\dom4j.xml"), of); List list = document.selectNodes(
"//PersonId[@name = 'chen_zhen']");
if (list.size() > 0)
{
org.dom4j.Element e = (org.dom4j.Element)list.get(0);
System.out.println(e.toString());
e.setAttributeValue("name", "huo_yuanjia");
e.setAttributeValue("age", "20");
e.setName("Fighter"); //改变tag
e.setText("0001"); //改变value
}
writer.write(document);
writer.close();
public void writeXML(String file,Document document,String encoding){
try{
FileWriter out = new FileWriter(new File(file));
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(encoding == null ? format.getEncoding() : encoding);
XMLWriter writer = new XMLWriter(out, format);
writer.write(document);
writer.close();
}
catch(IOException ex){
ex.printStackTrace();
}
}