以前的一个DOMAPI学习笔记,最近翻出来整理了一下,并将相关例程加了log4j。学习主要是参照IBM中国DevelopWorks的教程学的,具体见文后的参考文献。
一、几个认识
下面的orders.xml是DOM处理的对象。
<?xml version="1.0" encoding="UTF-8"?>
<orders xmlns="http://hedong.3322.org/DOMLearning/orderSystem.html">
<order>
<customerid limit="1000">12341</customerid>
<status>pending</status>
<item instock="Y" itemid="SA15">
<name>Silver Show Saddle, 16 inch</name>
<price>825.00</price>
<qty>1</qty>
</item>
<item instock="N" itemid="C49">
<name>Premium Cinch</name>
<price>49.00</price>
<qty>1</qty>
</item>
</order>
<order>
<customerid limit="150">251222</customerid>
<status>pending</status>
<item instock="Y" itemid="WB78">
<name>Winter Blanket (78 inch)</name>
<price>20</price>
<qty>10</qty>
</item>
</order>
</orders>
orders = null
[ Attribute: xmlns = http://hedong.3322.org/DOMLearning/orderSystem.html]
#text =
order = null
#text =
customerid = null
[ Attribute: limit = 1000]
#text = 12341
#text =
status = null
#text = pending
#text =
item = null
[ Attribute: instock = Y]
[ Attribute: itemid = SA15]
#text =
name = null
#text = Silver Show Saddle, 16 inch
#text =
price = null
#text = 825.00
#text =
qty = null
#text = 1
#text =
#text =
item = null
[ Attribute: instock = N]
[ Attribute: itemid = C49]
#text =
name = null
#text = Premium Cinch
#text =
price = null
#text = 49.00
#text =
qty = null
#text = 1
#text =
#text =
#text =
order = null
#text =
customerid = null
[ Attribute: limit = 150]
#text = 251222
#text =
status = null
#text = pending
#text =
item = null
[ Attribute: instock = Y]
[ Attribute: itemid = WB78]
#text =
name = null
#text = Winter Blanket (78 inch)
#text =
price = null
#text = 20
#text =
qty = null
#text = 10
#text =
#text =
#text =
在DOM中,Node和Element不是一回事,Node是Emlement的父类,NodeList是Node的集合。
2、例程可下载
输出结果在dom.log中。
参考文献:
理解DOM
http://www-900.ibm.com/developerWorks/cn/education/xml/x-udom/tutorial/index.html