package day28_XML_dtd;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class Dom_JaxpDemo {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
//创建工厂
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
//得到dom解析器(也就是document对象)
DocumentBuilder db= dbf.newDocumentBuilder();
//解析xml文档,得到代表文档的document;
Document doc=db.parse("src/book.xml");
//
NodeList nods=doc.getElementsByTagName("书架");
Node node = nods.item(0);
String s=node.getTextContent();
System.out.println(s);
}
}
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class Dom_JaxpDemo {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
//创建工厂
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
//得到dom解析器(也就是document对象)
DocumentBuilder db= dbf.newDocumentBuilder();
//解析xml文档,得到代表文档的document;
Document doc=db.parse("src/book.xml");
//
NodeList nods=doc.getElementsByTagName("书架");
Node node = nods.item(0);
String s=node.getTextContent();
System.out.println(s);
}
}