码迷,mamicode.com
首页 > 编程语言 > 详细

【自动化__持续集成】___java___XML__DOM添

时间:2017-09-08 00:26:23      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:user   tco   space   white   content   class   ati   bsp   name   

一、代码如下

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添

标签:user   tco   space   white   content   class   ati   bsp   name   

原文地址:http://www.cnblogs.com/wujianbo123/p/7492263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!