wmlprocessor.java~8~

来自「一个很好xml学习样例」· JAVA~8~ 代码 · 共 37 行

JAVA~8~
37
字号
package xmltest;
import javax.xml.parsers.*;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class WMLProcessor {
  public static void main(String[] args) {
    File xmlFile = new File("test.xml");
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder db = dbf.newDocumentBuilder();
      doc = db.parse(xmlFile);
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
    catch (SAXException ex) {
      ex.printStackTrace();
    }
    catch (ParserConfigurationException ex) {
      ex.printStackTrace();
    }
    Element root = doc.getDocumentElement();
   stepThrough(root);
  }

  private static void stepThrough(Node start){
    System.out.println(start.getNodeName() + " = " + start.getNodeValue());
    for (Node child = start.getFirstChild() ; child != null; child = child.getNextSibling()){
      stepThrough(child);
    }

  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?