zoukankan      html  css  js  c++  java
  • 【自动化__持续集成】___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)));
    		
    		
    
    	}
    
    }
    
  • 相关阅读:
    树---对称的二叉树
    树---二叉树的下一个节点
    阿里一面电话面
    树---重建二叉树
    CVTE电话面
    聊聊平台型游戏
    Ogre-next with Visual Studio 2019, SDL Memset, CL.exe error
    中国能不能制作AAA游戏?
    Simple Cel Shading 钟馗
    Modeling -> Mixamo auto rigging -> UE4 retargeting
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7492263.html
Copyright © 2011-2022 走看看