Package day06_parser.dom;/*** xml parsing technology: JAXP is the abbreviation of Java API for XML Processing. * The Chinese meaning is: programming Interface for XML document processing written in Java. JAXP supports DOM, SAX, XSLT, and other standards. * Below we study two ways of parsing: * 1. dom parsing 2. sax parsing: Simple API for XML * Below is an example of dom parsing. * JAXP-DOM parsing instance: * The following instance implements the function through javax. xml package implements dom-based xml parsing * specific operations include adding nodes, deleting nodes, modifying node content, and querying node information */import java. io. file; import javax. xml. parsers. *; import javax. xml. transform. *; import javax. xml. transform. dom. *; import javax. xml. transform. stream. streamResult; import org. junit. test; import org. w3c. dom. *; public class DOMCURD {// you can use the junit test tool to test public static void main (String [] args) throws Exception {demo05 ();} // obtain the Document object associated with the parser @ Testpublic static void demo01 () throws Exception {// ==================== get document ==================================== ========/// 1. obtain the factory DocumentBuilderFactory factory = DocumentBuilderFactory. newInstance (); // 2. obtain the parser DocumentBuilder builder = factory. newDocumentBuilder (); // 3. obtain the Document Object @ SuppressWarnings ("unused") Document document = builder Based on the parser. parse (new File ("db. xml ");} // query public static void demo02 () throws Exception {// 1. obtain documentDocumentBuilderFactory factory = DocumentBuilderFactory. newInstance (); DocumentBuilder builder = factory. newDocumentBuilder (); Document document = builder. parse (new File ("db. xml "); // 2. get the root Element -- books (can be omitted) @ SuppressWarnings ("unused") Element rootElement = document. getDocumentElement (); // 3. obtain all the book elements. The attribute idNodeList allBookElements = document. getElementsByTagName ("book"); // 4 traverse the book element ---- db of this instance. xml contains two book elements for (int I = 0; I