通过java程序对xml文件进行简单操作


123456
456789
10
123
132
nan

利用java程序进行操作



import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
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;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;

public class test1 {
	public static void main(String[] args) throws Exception {
//		printName();
	//	addNode();
		Modify();
	}
	//输出所有标签
	private static void printName() throws ParserConfigurationException,
			SAXException, IOException {
		DocumentBuilderFactory builderFactory= DocumentBuilderFactory.newInstance();
		DocumentBuilder  builder = builderFactory.newDocumentBuilder();
		Document document = builder.parse("src/4.xml");
		NodeList list = document.getElementsByTagName("name");
		for(int i=0;i

你可能感兴趣的:(xml)