I saw "Java and XML" finally got some gains, and immediately prepared a piece of code practicing. Use the DOM to get XML information. Write a simple XML file first. Tryxml.xml
XML Version = "1.0" encoding = "UTF-8"?>
EMP>
EMP_INFO>
Create a Java file named TRYXML
Import java.io. *;
Import org.xml.sax. *;
Import org.w3c.dom. *;
Import org.apache.xerces.Parsers.Dompival;
Public class tryxml {
Public void parsedoc (string URI) {try {domparser myparser = new domparser (); // build a worker myparser.parse (URI); // Analytical file Document XmLDoc = myparser.getDocument (); // Open a file PrintXML XMLDOC); // Output XML information} catch (ieException e) {system.out.println ("Error IOException !!!);} catch (saxexception e) {system.out.println (" Error SaxException !!! " }}
Public static void main (string [] args) {string uri = args [0];
Tryxml THEXML = New Tryxml (); THEXML.PARSEDOC (URI);
Public void printXML (Node node) {if (node.getnodetype () == node.document_node) {// node type When the file node. System.out.println ("XML Start"); nodelist nodelist = node.getChildNodes (); // Get subtitle.
IF (nodelist! = null) {for (int i = 0; i I have been compiled under the console. Then hit Java Tryxml tryxml.xml. what. Successful?