?? displaydeptxml.java
字號:
package firstjdom;//導入必要的包import java.io.*;import java.util.*;import org.jdom.*; //JDOM的類import org.jdom.input.*; //讀取XML的類 SAXimport org.jdom.output.*;//寫出XML文件//讀取XML文件 逐行顯示文件內容public class DisplayDeptXML{ public static void main(String[] args) throws Exception { //Builder //1. SAX的解析器 org.jdom.input.SAXBuilder saxb = new SAXBuilder(); //DTD驗證的有效性 //saxb.setValidation(true); //document //2.XML解析成Document //doc DOM樹 org.jdom.Document doc = saxb.build(new File("f:/order.xml")); //顯示DOM樹 //gb2312 顯示中文 //" " 層次顯示的時候帶縮進字符 //XML之間時候出現 空行 // org.jdom.output.XMLOutputter xmlout = // new XMLOutputter(" ",false,"gb2312"); //指定格式 //中文的時候 設定字符集GBK/ GB2312 Format fmt = Format.getPrettyFormat() ; fmt.setEncoding("GBK"); //指定輸出的格式 org.jdom.output.XMLOutputter xmlout = new XMLOutputter(fmt); //doc輸出到控制臺 //output方法輸出document 到控制臺 xmlout.output(doc,System.out); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -