1. Using dom to parse xml files in addition to using SAX to parse XML files, you can also use the familiar DOM to parse XML files. When DOM parses an XML file, it stores all the content of the XML file in the memory as a document tree, and then allows you to use DOM APIs to traverse the XML tree and retrieve the required data. The code that uses DOM to operate XML looks intuitive, and it is easier to code than to implement it based on SAX. However, because the DOM needs to store all the content of the XML file in the memory as a document tree, the memory consumption is relatively large, especially for mobile devices running Android, because the device resources are precious, we recommend that you use SAX to parse the XML file. Of course, if the content of the XML file is small, DOM is also a feasible code. Please refer to the remarks at the bottom of this page to import java. io. inputStream; import java. util. arrayList; import java. util. list; import javax. xml. parsers. documentBuilder; import javax. xml. parsers. documentBuilderFactory; import org. w3c. dom. document; import org. w3c. dom. element; import org. w3c. dom. node; import org. w3c. dom. nodeList; import cn. itcast. xml. domain. person;/*** use Dom to parse xml files **/public class DomXMLReader {public static List ReadXML (InputStream inStream ){ List Persons = new ArrayList (); DocumentBuilderFactory factory = DocumentBuilderFactory. newInstance (); try {DocumentBuilder builder = factory. newDocumentBuilder (); Document dom = builder. parse (inStream); Element root = dom. getDocumentElement (); NodeList items = root. getElementsByTagName ("person"); // find all person nodes for (int I = 0; I <items. getLength (); I ++) {Person person Person = new person (); // obtain the first Person node Element personNode = (Element) items. item (I); // get the id attribute value of the person node person. setId (new Integer (personNode. getAttribute ("id"); // obtain all subnodes under the person node (blank nodes and name/age elements between labels) NodeList childsNodes = personNode. getChildNodes (); for (int j = 0; j <childsNodes. getLength (); j ++) {Node node = (Node) childsNodes. item (j); // determines whether the element type is if (node. getNodeType () = Node. ELEMENT_NODE) {Element childNode = (Element) node; // determine whether the name Element if ("name ". equals (childNode. getNodeName () {// get the Text node under the name element, and then get the data person from the Text node. setName (childNode. getFirstChild (). getNodeValue ();} else if ("age ". equals (childNode. getNodeName () {person. setAge (new Short (childNode. getFirstChild (). getNodeValue () ;}} persons. add (person);} inStream. close ();} catch (Exception e) {e. printStackTrace ();} return persons ;}----------------------------------------------------------