?? samplejdom.java
字號:
package com.ajaxlab.ajax;
import org.jdom.*;
import org.jdom.output.*;
import java.io.*;
/**
* 展示如何使用JDOM的API創建XML文檔
* @author 柯自聰
* 2005-12-25
*/
public class SampleJDOM {
public SampleJDOM() {
}
public static void main(String[] args) {
//新建文檔對象
Document doc = new Document();
//新建根結點
Element book = new Element("book").setAttribute("title","Programming with Ajax");
Element chapter1 = new Element("chapter").setAttribute("name","Chapter1 About Ajax");
Element chapter2 = new Element("chapter").setAttribute("name","Chapter2 B/S Structure");
Element section1 = new Element("section").addContent("What is Ajax");
Element section2 = new Element("section").addContent("Definiens of Ajax");
Element section3 = new Element("section").addContent("HTTP Protocal");
Element section4 = new Element("section").addContent("Web Design Pattern");
//將子結點加入父結點
chapter1.addContent(section1);
chapter1.addContent(section2);
chapter2.addContent(section3);
chapter2.addContent(section4);
book.addContent(chapter1);
book.addContent(chapter2);
doc.addContent(book);
//將文檔輸出到控制臺
XMLOutputter outputter = new XMLOutputter();
try {
outputter.output(doc,System.out);
}catch(IOException ex) {
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -