大道致遠
前途漫漫
BlogJava
首頁
新隨筆
新文章
聯系
聚合
管理
posts - 4,comments - 0,trackbacks - 0
<
2025年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
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
1
2
3
4
5
-------------------------------
-------------------------------
常用鏈接
我的隨筆
我的評論
我的參與
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆檔案
(4)
2007年1月 (3)
2006年11月 (1)
最新隨筆
1.?Hashtable 的遍歷
2.?java NIO 傳對象
3.?ByteBuffer 轉化為 String
4.?DOM4J解析XML
搜索
最新評論
閱讀排行榜
1.?ByteBuffer 轉化為 String(6651)
2.?DOM4J解析XML(1365)
3.?Hashtable 的遍歷(1346)
4.?java NIO 傳對象(989)
評論排行榜
1.?Hashtable 的遍歷(0)
2.?java NIO 傳對象(0)
3.?ByteBuffer 轉化為 String(0)
4.?DOM4J解析XML(0)
DOM4J解析XML
Document?doc?
=
?
null
;
doc?
=
?DocumentHelper.createDocument();
//
添加根結點。
Element?root?
=
?doc.addElement(
"
root
"
);
//
為根結點添加子結點。
Element?child?
=
?root.addElement(
"
child
"
);
//
為節點添加屬性
child.addAttribute(
"
childattribute
"
,
"
attribute
"
);
//
為節點添加Text
child.setText(
"
Text
"
);
//
遍歷所有結點的方法
Element?element?
=
?doc.getRootElement();
public
?
void
?xmlIterator(Element?element)
{
???????
for
?(
int
?i?
=
?
0
,?size?
=
?element.nodeCount();?i?
<
?size;?i
++
)????
????????
{
???????????Node?node?
=
?element.node(i);
???????????
if
?(node?
instanceof
?Element)?
????????????
{
????????????????xmlIterator((Element)?node);
?????????????}
?
??????????}
??}
//
如果想不遍歷而得到某一節點,那么就要為每一個節點添加一個ID屬性
//
例如:Element.addAttribute("ID",id);
//
然后用以下方法即可。
Element?findElement?
=
?doc.elementByID(id);
posted on 2006-11-12 16:24
wyg405
閱讀(1365)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Copyright ©2025 wyg405 Powered By
博客園
模板提供:
滬江博客
主站蜘蛛池模板:
平陆县
|
扎囊县
|
五河县
|
若尔盖县
|
大庆市
|
黄山市
|
江华
|
铁岭市
|
绥阳县
|
汝州市
|
西藏
|
九寨沟县
|
依安县
|
嵊州市
|
五指山市
|
长子县
|
石家庄市
|
海盐县
|
德州市
|
年辖:市辖区
|
安远县
|
三台县
|
齐河县
|
汤阴县
|
铁岭县
|
太保市
|
莒南县
|
石城县
|
平乡县
|
叶城县
|
江达县
|
边坝县
|
平遥县
|
南投县
|
勐海县
|
香河县
|
鄂州市
|
滨海县
|
都昌县
|
镇平县
|
耒阳市
|