⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmlprocessor.java~7~

📁 一个很好xml学习样例
💻 JAVA~7~
字号:
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();
    System.out.println("The root element is: " + root.getNodeName());
    NodeList children = root.getChildNodes();
    System.out.println("There are " + children.getLength() + " nodes in the doc");

  }

  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -