【自动化__持续集成】___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)));

	}

}
时间: 2024-10-19 20:11:06

【自动化__持续集成】___java___XML__DOM添的相关文章

【自动化__持续集成】___java___List

一.代码如下 package www.wujianbotwo; import java.util.*; public class Demo07 { public static void main(String[] args) { // TODO Auto-generated method stub List mylist= new List(); } } package www.wujianbotwo; import java.util.*; public class Demo07 { publ

【自动化__持续集成】___java___文本文件__字节流

一.代码如下 package www.wujianbotwo; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; public class Demo09 { public static void main(String[] args) { // TODO

【自动化__持续集成】___java___字符串转数组

一.代码如下 package www.wujianbotwo; public class Demo08 { public static void main(String[] args) { // TODO Auto-generated method stub String content= "wujianbo,wujianob,33333"; String[] ud= content.split(",");//将字符串分段成一个数组 for(int i=0; i&l

【自动化__持续集成】___java___XMl___DOM读

一.代码如下 package com.wujianbo.five; import javax.sound.midi.Sequence; import javax.xml.bind.Element; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; import

【自动化__持续集成】___java___重写

一.代码如下 package www.wujianbotwo; class Door { int height= 200; int weight= 80; String material= "实木"; private void open() { // TODO Auto-generated method stub System.out.println("开门"); } public void close() { // TODO Auto-generated meth

【自动化__持续集成】___java___继承

一.代码如下 package www.wujianbotwo; class Door { int height= 200; int weight= 80; String material= "实木"; public void open() { // TODO Auto-generated method stub System.out.println("开门"); } public void close() { // TODO Auto-generated metho

【自动化__持续集成】___java___excel__jxl改

一.代码如下 package com.wujianbo.five; import java.awt.HeadlessException; import java.awt.Label; import java.io.File; import java.io.IOException; import jxl.Workbook; import jxl.read.biff.BiffException; import jxl.write.WritableSheet; import jxl.write.Wri

【自动化__持续集成】___java___excel__jxl读

一.代码如下 package com.wujianbo.five; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.demo.Demo; import jxl.read.bif

【自动化__持续集成】___java___正则表达式

一.代码如下 package com.wujianbo.five; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo01 { public static void main(String[] args) { // TODO Auto-generated method stub String phone= "13541433525"; String phoneEx= &quo