Get XML information first step by Java

xiaoxiao2021-03-06  74

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

3

Personnel Department

32

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?

转载请注明原文地址:https://www.9cbs.com/read-93789.html

New Post(0)