Eclipse下jdom配置及用之生成、解析xml文档

本文介绍了如何在Eclipse环境下配置JDOM库,解决访问限制问题,并提供了生成与解析XML文档的示例代码,展示了创建XML文档结构以及读取XML内容的基本步骤。
摘要由CSDN通过智能技术生成

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");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值