zgli
BlogJava
首頁
新文章
新隨筆
聚合
管理
posts - 35, comments - 7, trackbacks - 0
jdom的簡單使用
?
import
?java.io.FileOutputStream;
import
?java.util.List;
import
?org.jdom.Attribute;
import
?org.jdom.Document;
import
?org.jdom.Element;
import
?org.jdom.input.SAXBuilder;
import
?org.jdom.output.Format;
import
?org.jdom.output.XMLOutputter;
public
?
class
?XML?
{
????
public
?
static
?
void
?main(String[]?args)?
throws
?Exception?
{
????????SAXBuilder?builder?
=
?
new
?SAXBuilder();
????????Document?doc?
=
?builder.build(
"
d:\\destination.xml
"
);
????????Element?root?
=
?doc.getRootElement();
????????root.removeChild(
"
Target
"
);
????????Element?items?
=
?root.getChild(
"
Items
"
);
????????List?item?
=
?items.getChildren(
"
item
"
);
????????
for
?(
int
?i?
=
?
0
;?i?
<
?item.size();?i
++
)?
{
????????????Element?elem?
=
?(Element)?item.get(i);
????????????Attribute?attr?
=
?elem.getAttribute(
"
displayName
"
);????????????
????????????attr.setValue(attr.getValue()?
+
?
"
中國
"
);????????????
????????}
????????
//
?保存
????????Format?format?
=
?Format.getCompactFormat();
????????format.setEncoding(
"
gb2312
"
);
????????format.setIndent(
"
??
"
);
????????XMLOutputter?XMLOut?
=
?
new
?XMLOutputter(format);
????????XMLOut.output(doc,?
new
?FileOutputStream(
"
d:\\destination_tmp.xml
"
));
????}
}
posted on 2006-05-13 09:22
java小記
閱讀(225)
評論(0)
編輯
收藏
所屬分類:
原創
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
<
2006年5月
>
日
一
二
三
四
五
六
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
8
9
10
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆分類
原創(1)
轉載(8)
隨筆檔案
2006年5月 (6)
2006年4月 (4)
2006年3月 (2)
2006年2月 (8)
2006年1月 (5)
2005年12月 (5)
2005年11月 (5)
搜索
最新評論
1.?re: spring的DataSource事務郁悶了我兩天[未登錄]
你救了我呀,我倒沒有郁悶2天,只有一天
--eric
2.?re: XP的Administrator用戶和自動登陸問題
好,謝謝。
--lin
3.?re: About VoIP ?
評論內容較長,點擊標題查看
--國際長途電話站
4.?re: 關于spring的事務管理(單數據庫):純屬猜測。
cx
--桂豐大廈
5.?re: spring的DataSource事務郁悶了我兩天
我很同情你~我也是啊~
--我是大俠~
閱讀排行榜
1.?XP的Administrator用戶和自動登陸問題(5289)
2.?Tomcat加大內存設置從windows服務啟動不生效的問題(3293)
3.?如何防止swing窗口改變大小和最小化(2712)
4.?關于java虛擬機使用內存的思考(1891)
5.?spring的DataSource事務郁悶了我兩天(1564)
評論排行榜
1.?XP的Administrator用戶和自動登陸問題(3)
2.?spring的DataSource事務郁悶了我兩天(2)
3.?About VoIP ?(1)
4.?關于spring的事務管理(單數據庫):純屬猜測。(1)
5.?PasswordManager--從AES看到的有用代碼片段(0)
Copyright ©2025 java小記 Powered By
博客園
模板提供:
滬江博客
主站蜘蛛池模板:
阿拉善右旗
|
屏东市
|
定西市
|
芦山县
|
孟津县
|
邳州市
|
新宁县
|
东宁县
|
石河子市
|
社旗县
|
桑日县
|
玉环县
|
项城市
|
阿荣旗
|
瑞安市
|
呼图壁县
|
兴城市
|
香港
|
马公市
|
临沭县
|
南华县
|
松阳县
|
桐柏县
|
雷波县
|
凯里市
|
宁强县
|
凌海市
|
屏东县
|
永兴县
|
荆门市
|
南靖县
|
湛江市
|
库尔勒市
|
嘉定区
|
昌吉市
|
郓城县
|
宣武区
|
昭平县
|
徐汇区
|
德江县
|
义乌市
|