java jdom jar_jdom jar下载_jdom jar官方下载-太平洋下载中心

be4591bb3071aad13292cbadb1a9f221.png

不用是你的损失!这么好用的包

本Jive(Jdon版)可在Jbuilder 7直接打开。

建议你用Jbuilder7打开后,编辑相应设置(JDK1.4)

本软件在linux+jdk1.4+tomcat 4以上环境运行正常,中文显示正常。

用法:

依赖于jar包: dom4j.jar 和 jaxen-1.1.1.jar

Xml代码

1. <?xml version="1.0" encoding="UTF-8"?>

2.

3. D:\\index\\IndexDB

4.

Java代码

1. package com.wlh.dom4j.test;

2.

3. import org.dom4j.Document;

4. import org.dom4j.DocumentException;

5. import org.dom4j.Node;

6. import org.dom4j.io.SAXReader;

7.

8. public class TestReader {

9.  public static void main(String args[]){

10.  String filePath="index.xml";

11.  try {

12.  //如果配置文件是在Src下,则采用如下方式得到Document

13.  Document document=new SAXReader().read(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));

14.  //如果配置文件是在本地文件系统,则采用如下方式得到Document

15.  //Document document=new SAXReader().read("D:\\index.xml");

16.  if (document == null) {

17.  System.out.println(filePath+"没找到");

18.  }else{

19.  Node node=document.selectSingleNode("//list/index");

20.  String indexfile=node.getText();

21.  System.out.println(indexfile);

22.  }

23.  } catch (DocumentException e) {

24.  e.printStackTrace();

25.

26.  }

27.  }

28. }

jdom读取xml文件:

依赖于jar包: jdom.jar

得到URL的方式:Thread.currentThread().getContextClassLoader().getResource(filePath)

Java代码

1. package com.wlh.dom4j.test;

2.

3. import java.io.IOException;

4. import java.util.List;

5.

6. import org.jdom.Document;

7. import org.jdom.Element;

8. import org.jdom.JDOMException;

9. import org.jdom.input.SAXBuilder;

10.

11. public class TestJdomReader {

12.  public static void main(String args[]) {

13.  String filePath = "zxt_index.xml";

14.  String indexPath="";

15.  SAXBuilder builder = new SAXBuilder(false);

16.  try {

17.  Document doc = builder.build(Thread.currentThread().getContextClassLoader().getResource(filePath));

18.  Element books = doc.getRootElement();

19.  Element rootElement= books.getChild("list");

20.  Element index=rootElement.getChild("index");

21.  indexPath=index.getText();

22.  System.out.println(indexPath);

23.  } catch (JDOMException e) {

24.  e.printStackTrace();

25.  } catch (IOException e) {

26.  e.printStackTrace();

27.  }

28.

29.  }

30. }

5f5212bd6db58eb2d410cc977a80b3d8.gif

软件截图1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值