java_java写XML文件和读取XML文件

网络上的优秀资源,经过整编,更容易阅读与记忆

java XML XML

DOM Java XML :

DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();

DocumentBuilder builder=dbf.newDocumentBuilder(); DocumentBuilder Parse() XML Document Document

XML

Document doc=builder.parse("candiate.xml");

Document getElementsByTagName() NodeList XML

NodeList item() Node

NodeList nl=doc.getElementsByTagName("PERSON"); Element node=(Element)nl.item(i);

Node getNodeValue()

node.getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue()

:

package net.fygk.test; import java.io.File; import javax.xml.parsers.*; import org.w3c.dom.*; public class dom { public static void main(String args[]) { //String uri=new File("person.xml");//args[0]; try{ DocumentBuilderFactory factory

=DocumentBuilderFactory.newInstance();//

DocumentBuilder

builder=factory.newDocumentBuilder();//

Document doc=builder.parse(new File("test.xml"));// Document

System.out.println(doc.getImplementation());

java_java写XML文件和读取XML文件相关文档

最新文档

返回顶部