使用dom4j技術來讀取xml中的資訊。

2021-08-17 05:04:56 字數 347 閱讀 8370

然後新建乙個saxreader物件

使用saxreader物件使用read方法讀取到xml獲得document文件

通過document文件獲取到根節點getrootelemnet()

然後通過根節點的遍歷方法獲得遍歷後的集合elementiterator();

遍歷集合將集合中各個物件的屬性值取出來attributevalue();

接著再根據這個節點向下遍歷,獲得這個節點連線的下一層的遍歷集合

迴圈遍歷直至遍歷完全

public void test()

}}catch(exception e)

}

dom4j讀取XML簡單使用

測試例子1 suppresswarnings unchecked public class testdom4j 得到文件的document param is return throws documentexception public static document getdocument inpu...

dom4j 使用dom4j生成xml

使用org.dom4j.element 建立xml 生成service.xml檔案 param tran 交易物件 param filepath 資料夾路徑 public static void exportservicexml listtranlist,string filepath servic...

Dom4j讀取xml檔案

一 xml檔案 1.0 encoding utf 8 chenleixing date 2015 02 15 張三24 男 zhangxiaochao date 2015 02 15 李四24 女 二 建立file,獲取根節點 獲取檔案的document物件,然後獲取對應的根節點 author ch...