jdomjar 免費版

2024-07-18發(fā)布者:wx20230305205025大小: 下載:0

文件大小:

軟件介紹

jdom jar:免費的jdom.jar包,非常好用的包,錯過了將是你最大的損失。本Jive(Jdon版)可在Jbuilder 7直接打開。建議你用Jbuilder7打開后,編輯相應設置(JDK1.4)。本軟件在linux+jdk1.4+tomcat 4以上環(huán)境運行正常,中文顯示正常。

【jdom.jar用法】


依賴于jar包: dom4j.jar 和 jaxen-1.1.1.jar
Xml代碼
<?xml version="1.0" encoding="UTF-8"?>
<list>
<index>D:\\index\\IndexDB</index>
</list>

【Java代碼】

package com.wlh.dom4j.test;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class TestReader {
public static void main(String args[]){
String filePath="index.xml";
try {
//如果配置文件是在Src下,則采用如下方式得到Document
Document document=new SAXReader().read(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));
//如果配置文件是在本地文件系統(tǒng),則采用如下方式得到Document
//Document document=new SAXReader().read("D:\\index.xml");
if (document == null) {
System.out.println(filePath+"沒找到");
}else{
Node node=document.selectSingleNode("//list/index");
String indexfile=node.getText();
System.out.println(indexfile);
}
} catch (DocumentException e) {
e.printStackTrace();

}
}
}

【jdom讀取xml文件】

依賴于jar包: jdom.jar
得到URL的方式:Thread.currentThread().getContextClassLoader().getResource(filePath)
Java代碼
package com.wlh.dom4j.test;

import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class TestJdomReader {
public static void main(String args[]) {
String filePath = "zxt_index.xml";
String indexPath="";
SAXBuilder builder = new SAXBuilder(false);
try {
Document doc = builder.build(Thread.currentThread().getContextClassLoader().getResource(filePath));
Element books = doc.getRootElement();
Element rootElement= books.getChild("list");
Element index=rootElement.getChild("index");
indexPath=index.getText();
System.out.println(indexPath);
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {image.png
發(fā)表評論(共0條評論)
請自覺遵守互聯(lián)網(wǎng)相關政策法規(guī),評論內(nèi)容只代表網(wǎng)友觀點,發(fā)表審核后顯示!

版權聲明:

1 本站所有資源(含游戲)均是軟件作者、開發(fā)商投稿,任何涉及商業(yè)盈利目的均不得使用,否則產(chǎn)生的一切后果將由您自己承擔!

2 本站將不對任何資源負法律責任,所有資源請在下載后24小時內(nèi)刪除。

3 若有關在線投稿、無法下載等問題,請與本站客服人員聯(lián)系。

4 如侵犯了您的版權、商標等,請立刻聯(lián)系我們并具體說明情況后,本站將盡快處理刪除,聯(lián)系QQ:2499894784

返回頂部