自动化__持续集成___java___XML__DOM添
Posted 18513757531
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化__持续集成___java___XML__DOM添相关的知识,希望对你有一定的参考价值。
一、代码如下
package com.wujianbo.five; import java.io.File; import java.security.cert.TrustAnchor; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Demo09 { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Demo09 demo09= new Demo09(); demo09.createXmlByDom(); } private void createXmlByDom() throws Exception { // TODO Auto-generated method stub DocumentBuilderFactory dbf= DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); String xmlName= System.getProperty("user.dir") + "\\data\\NewStudents.xml"; //System.out.println(xmlName); DocumentBuilder db= dbf.newDocumentBuilder(); //System.out.println(db); Document doc= db.parse(xmlName); // Element root= doc.getDocumentElement(); // Element son= doc.createElement("son"); // son.setAttribute("id", "001"); // Element name= doc.createElement("name"); // name.setTextContent("儿子"); // son.appendChild(name); // Element age= doc.createElement("age"); // age.setTextContent("10"); // son.appendChild(age); // // root.appendChild(son); // // TransformerFactory factory= TransformerFactory.newInstance(); // Transformer former= factory.newTransformer(); // former.transform(new DOMSource(doc), new StreamResult(new File(xmlName))); } }
以上是关于自动化__持续集成___java___XML__DOM添的主要内容,如果未能解决你的问题,请参考以下文章