1、jdom配置:
由官方网站下载jdom最新版本,将之加入E:\Eclipse\jre\lib\ext. 在eclipse下import org.jdom2.*; ,即可成功。不过在引入类时,最好使用单类型引入。
2、eclipse 设置
在用语句:Document doc=new Document(); 创建文档时,发现Document类不可访问,因为有些库的访问被限制,不知为何。
设置方法如下:Eclipse 菜单Windows---->Preferences---->Java----->Compiler------>Error/Warnings----->Deprecated and Restrict ed API------>Forbidden references----->Warnings.
3. 生成XML文件源代码
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Node{
public static void main(String[] args)
{
Document doc=new Document();
Element book=new Element("book");
book.setAttribute("title", "A");