狂蟲臭博
我是java界的一只臭蟲!!!
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
posts - 21, comments - 6, trackbacks - 0
公告
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆檔案
(21)
2007年1月 (1)
2006年12月 (1)
2006年10月 (1)
2006年9月 (18)
文章分類
(2)
DOM4J(2)
文章檔案
(2)
2006年9月 (2)
CLASSMATE
FRIENDS
我是大頭,心情下的天空
耗子
Net-Superior
Appfuse in China
e代劍客
NEUSOFT
豆豆龍
suse web
Official-WEB
AppFuse
Matt Raible 開發的一個指導性的入門級J2EE框架
搜索
積分與排名
積分 - 10222
排名 - 2365
最新評論
1.?re: 中國作家是為了什麼而出書???
評論內容較長,點擊標題查看
--小車馬
2.?re: Ajax進階書籍
@心內求法
激勵的話,呵呵.......
--Warren.Wu
3.?re: Ajax進階書籍
對了,公告里的日語是什么意思啊?
--心內求法
4.?re: Ajax進階書籍
夠多的,可以開書店了,呵呵
--心內求法
5.?re: Ant的參數輸入問題
@lala
Thanks
--Warren.Wu
閱讀排行榜
1.?Ant的參數輸入問題(3008)
2.?eclipse查看jdk源碼(1062)
3.?DOM編程詳解(612)
4.?jdom讀取xml(542)
5.?Ubuntu安裝Skype(429)
評論排行榜
1.?Ajax進階書籍(3)
2.?Ant的參數輸入問題(2)
3.?中國作家是為了什麼而出書???(1)
4.?惡心的Date(0)
5.?[轉]java數據庫連接(0)
dom4j基本代碼
??1
package
?dom;
??2
??3
import
?java.io.File;
??4
import
?java.io.FileWriter;
??5
??6
import
?org.dom4j.Document;
??7
import
?org.dom4j.DocumentHelper;
??8
import
?org.dom4j.Element;
??9
import
?org.dom4j.Node;
?10
import
?org.dom4j.io.SAXReader;
?11
import
?org.dom4j.io.XMLWriter;
?12
?13
/**?*/
/**
?14
?*?
@author
??~@_@
?15
?
*/
?16
public
?
class
?Dom4jDemo?
{
?17
????
/**?*/
/**
?XML文件路徑?
*/
?18
????
private
?String?XMLPath?
=
?
null
;
?19
?20
????
/**?*/
/**
?XML文檔?
*/
?21
????
private
?Document?document?
=
?
null
;
?22
?23
????
public
?Dom4jDemo()?
{
?24
????}
?25
?26
????
/**?*/
/**
?27
?????*??初始化xml文件
?28
?????*?
?29
?????*?
@param
?XMLPath?文件路徑
?30
?????
*/
?31
????
public
?Dom4jDemo(String?XMLPath)?
{
?32
????????
this
.XMLPath?
=
?XMLPath;
?33
????}
?34
?35
????
/**?*/
/**
?*?打開文檔?
*/
?36
????
public
?
void
?openXML()?
{
?37
????????
try
?
{
?38
????????????SAXReader?reader?
=
?
new
?SAXReader();
?39
????????????
this
.document?
=
?reader.read(
this
.XMLPath);
?40
????????????System.out.println(
"
openXML()?successful?
"
);
?41
????????}
?
catch
?(Exception?e)?
{
?42
????????????System.out.println(
"
openXML()?Exception:
"
?
+
?e.getMessage());
?43
????????}
?44
????}
?45
?46
????
/**?*/
/**
?47
?????*??創建文檔
?48
?????*?
?49
?????*?
@param
?rootName?根節點名稱
?50
?????
*/
?51
????
public
?
void
?createXML(String?rootName)?
{
?52
????????
try
?
{
?53
????????????
this
.document?
=
?DocumentHelper.createDocument();
?54
????????????Element?root?
=
?document.addElement(rootName);
?55
????????????System.out.println(
"
createXML()?successful
"
);
?56
????????}
?
catch
?(Exception?e)?
{
?57
????????????System.out.println(
"
createXML()?Exception:
"
?
+
?e.getMessage());
?58
????????}
?59
????}
?60
?61
????
/**?*/
/**
?62
?????*??添加根節點的child
?63
?????*?
?64
?????*?
@param
?nodeName?節點名
?65
?????*?
@param
?nodeValue?節點值
?66
?????
*/
?67
????
public
?
void
?addNodeFromRoot(String?nodeName,?String?nodeValue)?
{
?68
????????Element?root?
=
?
this
.document.getRootElement();
?69
????????Element?level1?
=
?root.addElement(nodeName);
?70
????????level1.addText(nodeValue);
?71
????}
?72
?73
????
/**?*/
/**
?74
?????*??打開文檔
?75
?????*?
?76
?????*?
@param
?filePath?文檔路徑
?77
?????
*/
?78
????
public
?
void
?openXML(String?filePath)?
{
?79
????????
try
?
{
?80
????????????SAXReader?saxReader?
=
?
new
?SAXReader();
?81
????????????
this
.document?
=
?saxReader.read(filePath);
?82
????????????System.out.println(
"
openXML(String?filePath)?successful?
"
);
?83
????????}
?
catch
?(Exception?e)?
{
?84
????????????System.out.println(
"
openXML()?Exception:
"
?
+
?e.getMessage());
?85
????????}
?86
????}
?87
?88
????
/**?*/
/**
?保存文檔?
*/
?89
????
public
?
void
?saveXML()?
{
?90
????????
try
?
{
?91
????????????XMLWriter?output?
=
?
new
?XMLWriter(
new
?FileWriter(
new
?File(
?92
????????????????????
this
.XMLPath)));
?93
????????????output.write(document);
?94
????????????output.close();
?95
????????????System.out.println(
"
saveXML()?successful?
"
);
?96
????????}
?
catch
?(Exception?e1)?
{
?97
????????????System.out.println(
"
saveXML()?Exception:
"
?
+
?e1.getMessage());
?98
????????}
?99
????}
100
101
????
/**?*/
/**
102
?????*??保存文檔
103
?????*?
104
?????*?
@param
?toFilePath?保存路徑
105
?????
*/
106
????
public
?
void
?saveXML(String?toFilePath)?
{
107
????????
try
?
{
108
????????????XMLWriter?output?
=
?
new
?XMLWriter(
new
?FileWriter(
109
????????????????????
new
?File(toFilePath)));
110
????????????output.write(document);
111
????????????output.close();
112
????????}
?
catch
?(Exception?e1)?
{
113
????????????System.out.println(
"
saveXML()?Exception:
"
?
+
?e1.getMessage());
114
????????}
115
????}
116
117
????
/**?*/
/**
118
?????*??獲得某個節點的值
119
?????*?
120
?????*?
@param
?nodeName?節點名稱
121
?????
*/
122
????
public
?String?getElementValue(String?nodeName)?
{
123
????????
try
?
{
124
????????????Node?node?
=
?document.selectSingleNode(
"
//
"
?
+
?nodeName);
125
????????????
return
?node.getText();
126
????????}
?
catch
?(Exception?e1)?
{
127
????????????System.out
128
????????????????????.println(
"
getElementValue()?Exception:
"
?
+
?e1.getMessage());
129
????????????
return
?
null
;
130
????????}
131
????}
132
133
????
/**?*/
/**
134
?????*??獲得某個節點的子節點的值
135
?????*?
136
?????*?
@param
?nodeName
137
?????*?
@param
?childNodeName
138
?????*?
@return
139
?????
*/
140
????
public
?String?getElementValue(String?nodeName,?String?childNodeName)?
{
141
????????
try
?
{
142
????????????Node?node?
=
?
this
.document.selectSingleNode(
"
//
"
?
+
?nodeName?
+
?
"
/
"
143
????????????????????
+
?childNodeName);
144
????????????
return
?node.getText();
145
????????}
?
catch
?(Exception?e1)?
{
146
????????????System.out
147
????????????????????.println(
"
getElementValue()?Exception:
"
?
+
?e1.getMessage());
148
????????????
return
?
null
;
149
????????}
150
????}
151
152
????
/**?*/
/**
153
?????*??設置一個節點的text
154
?????*?
155
?????*?
@param
?nodeName?節點名
156
?????*?
@param
?nodeValue?節點值
157
?????
*/
158
????
public
?
void
?setElementValue(String?nodeName,?String?nodeValue)?
{
159
????????
try
?
{
160
????????????Node?node?
=
?
this
.document.selectSingleNode(
"
//
"
?
+
?nodeName);
161
????????????node.setText(nodeValue);
162
????????}
?
catch
?(Exception?e1)?
{
163
????????????System.out
164
????????????????????.println(
"
setElementValue()?Exception:
"
?
+
?e1.getMessage());
165
????????}
166
????}
167
168
????
/**?*/
/**
169
?????*??設置一個節點值
170
?????*?
171
?????*?
@param
?nodeName?父節點名
172
?????*?
@param
?childNodeName?節點名
173
?????*?
@param
?nodeValue?節點值
174
?????
*/
175
????
public
?
void
?setElementValue(String?nodeName,?String?childNodeName,
176
????????????String?nodeValue)?
{
177
????????
try
?
{
178
????????????Node?node?
=
?
this
.document.selectSingleNode(
"
//
"
?
+
?nodeName?
+
?
"
/
"
179
????????????????????
+
?childNodeName);
180
????????????node.setText(nodeValue);
181
????????}
?
catch
?(Exception?e1)?
{
182
????????????System.out
183
????????????????????.println(
"
setElementValue()?Exception:
"
?
+
?e1.getMessage());
184
????????}
185
????}
186
}
posted on 2006-09-20 15:45
Warren.Wu
閱讀(197)
評論(0)
編輯
收藏
所屬分類:
DOM4J
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
相關文章:
dom4j分析
dom4j基本代碼
Powered by:
BlogJava
Copyright ©2025 Warren.Wu
主站蜘蛛池模板:
99久热只有精品视频免费看
|
亚洲av无码一区二区三区网站
|
无遮挡呻吟娇喘视频免费播放
|
四虎国产精品永久免费网址
|
亚洲国产美女精品久久久久
|
免费大片黄手机在线观看
|
亚洲免费观看网站
|
免费**毛片在线播放直播
|
少妇人妻偷人精品免费视频
|
亚洲午夜无码久久久久小说
|
**一级毛片免费完整视
|
亚洲AV成人精品日韩一区
|
精品久久香蕉国产线看观看亚洲
|
亚洲乱码一二三四五六区
|
免费久久精品国产片香蕉
|
99re免费99re在线视频手机版
|
久久人午夜亚洲精品无码区
|
亚洲视频中文字幕
|
亚洲一区视频在线播放
|
国产乱码免费卡1卡二卡3卡
|
成人毛片100免费观看
|
久久久久亚洲精品天堂久久久久久
|
亚洲AV永久无码天堂影院
|
亚洲精品无码午夜福利中文字幕
|
大地资源在线观看免费高清
|
a级毛片100部免费观看
|
亚洲无线观看国产精品
|
久久这里只精品热免费99
|
精品亚洲成a人在线观看
|
亚洲综合婷婷久久
|
伊人久久大香线蕉亚洲
|
久久久久久免费一区二区三区
|
337p日本欧洲亚洲大胆精品555588
|
国产美女被遭强高潮免费网站
|
三级网站在线免费观看
|
亚洲AV成人无码网天堂
|
亚洲国产成人久久综合一区
|
亚洲精品无码Av人在线观看国产
|
精品亚洲成a人片在线观看
|
亚洲午夜精品久久久久久浪潮
|
成人免费视频试看120秒
|