Dom4j操作xml檔案

2021-10-10 07:08:22 字數 2275 閱讀 1707

>

>

dom4jgroupid

>

>

dom4jartifactid

>

>

1.6.1version

>

dependency

>

>

author

="天蠶土豆"

>

>

鬥破蒼穹name

>

>

86price

>

book

>

author

="蕭潛"

>

>

縹緲之旅name

>

>

92price

>

book

>

author

="蕭鼎"

>

>

誅仙name

>

>

98price

>

book

>

author

="天下霸唱"

>

>

鬼吹燈name

>

>

124price

>

book

>

author

="辰東"

>

>

神墓name

>

>

128price

>

book

>

books

>

@test

void

contextloads()

//指定檔案輸出的位置

fileoutputstream out =

newfileoutputstream

(filename)

;// 指定文字的寫出的格式:

outputformat format = outputformat.

createprettyprint()

;//漂亮格式:有空格換行

format.

setencoding

("utf-8");

//1.建立寫出物件

xmlwriter writer =

newxmlwriter

(out, format)

;//2.寫出document物件

writer.

write

(document)

;//3.關閉流

writer.

close()

;}catch

(exception e)

}

控制台
縹緲之旅 蕭潛 92

詭秘之主 愛潛水的烏賊 300

鬼吹燈 天下霸唱 124

神墓 辰東 128

龍族 江南 199

xml檔案
<?xml version="1.0" encoding="utf-8"?>

>

author

="蕭潛"

>

>

縹緲之旅name

>

>

92price

>

book

>

author

="愛潛水的烏賊"

>

>

詭秘之主name

>

>

300price

>

book

>

author

="天下霸唱"

>

>

鬼吹燈name

>

>

124price

>

book

>

author

="辰東"

>

>

神墓name

>

>

128price

>

book

>

author

="江南"

>

>

龍族name

>

>

199price

>

book

>

books

>

dom4j操作 xml檔案

父類 public class ba mlconfig public static void initconfig string rootelement,file xmlconfig throws exception fileoutputstream fos new fileoutputstream...

dom4j 操作XML檔案

簡單說,xpath就是選擇xml檔案中節點的方法。所謂節點 node 就是xml檔案的最小構成單位,一共分成7種。element 元素節點 attribute 屬性節點 text 文字節點 namespace 命名空間節點 processing instruction 處理命令節點 comment ...

dom4j 使用dom4j生成xml

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