为什么非要用dom加,用普通的文本文件操作就可以了
解决方案 »
- 求助!急急急~
- 菜鸟求助 Unknown Source 怎么解决?
- SSH中传值到jsp页面后,使用iterator输出失败--在线求解答!
- 新手求教!myeclipse怎么调试
- struts2 iterator标签内取值的问题
- Spring
- 问个简单问题 axis2实现webservice可以向服务器端传HashMap参数吗?
- Source not found for JspServletWrapper.handleJspException(Exception) line: 473
- 学JAVA可以跳过JSP吗?
- hibernate配置错误-org.hibernate.MappingNotFoundException
- struts2在tomcat中启动报错
- 怎样给xml文档添加声明?
先string拼装 再转为document对象也是可以的啊
这样貌似不可以。
Document不能加如像TEXT,Cdata类型的对象的
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
DocumentType type = impl.createDocumentType("beans", "-//SPRING//DTD BEAN 2.0//EN", "http://www.springframework.org/dtd/spring-beans-2.0.dtd");
Document document = impl.createDocument("shonetown", "root", type);
Element root = document.getDocumentElement();
Element child = document.createElement("new");
child.setTextContent("ddddddddd");
root.appendChild(child);
DOMWriter writer = new DOMWriterImpl(false);
writer.setNewLine("\r\n");
writer.setEncoding("UTF-8");
writer.writeNode(new FileOutputStream("d:\\1.xml"), document);