📄 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 + -