samplejdom.java

来自「《Ajax开发精要〉〉该书详细的介绍了关于Ajax和java相关的开发知识」· Java 代码 · 共 42 行

JAVA
42
字号
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 + =
减小字号Ctrl + -
显示快捷键?