DOM方式:
package DomTest import java.io.File import java.io.IOException import javax.xml.parsers.DocumentBuilder import javax.xml.parsers.DocumentBuilderFactory import javax.xml.parsers.ParserConfigurationException import javax.xml.transform.OutputKeys import javax.xml.transform.Transformer import javax.xml.transform.TransformerConfigurationException import javax.xml.transform.TransformerException import javax.xml.transform.TransformerFactory import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult import org.w3c.dom.Document import org.w3c.dom.Element import org.w3c.dom.NamedNodeMap import org.w3c.dom.Node import org.w3c.dom.NodeList import org.xml.sax.SAXException public class DOMTest { public void creatXML(){
DocumentBuilder db=getDocumentBuilder() Document document=db.newDocument() document.setXmlStandalone(true) //建立根節點
Element bookstore= document.createElement("bookStore") //新增子節點book
Element book=document.createElement("book") //新增子節點name
Element name=document.createElement("name") book.appendChild(name) //新增子節點內容
name.setTextContent("人猿泰山") book.setAttribute("id", "1") //將book子節點新增到bookstore中
bookstore.appendChild(book) //將bookstore節點(已包含book)新增到dom數中
document.appendChild(bookstore) //
TransformerFactory tff=TransformerFactory.newInstance() try {
Transformer tf=tff.newTransformer() //讓DOM樹輸出過程中正常換行
tf.setOutputProperty(OutputKeys.INDENT, "yes") tf.transform(new DOMSource(document), new StreamResult(new File("books1.xml"))) } catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
}
public static DocumentBuilder getDocumentBuilder(){
// 建立一個DocumentBuilderFactory物件
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance() // 建立DocumentBuilder物件
DocumentBuilder db=null try {
db = dbf.newDocumentBuilder() } catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
return db }
public static void main(String[] args) {
// 建立一個DocumentBuilder的物件
try {
// 透過DocumentBuilder物件的parse方法載入books.xml檔案
// 到當前專案下
Document document = getDocumentBuilder().parse("books.xml") // 獲取所有book節點的集合
NodeList bookList = document.getElementsByTagName("book") //透過nodeList的getLength()方法獲取bookLIst的長度
System.out.println("一共有:"+bookList.getLength()+"本書") //便利各個book節點
for (int i = 0 System.out.println("++++++++++++開始遍歷第"+(i+1)+"本書+++++++++++") //方式一,不知道有多少節點,透過迴圈來遍歷所有節點。
//透過 item(i)獲取一個book節點,nodeList
Node book=bookList.item(i) //獲取book的屬性的集合
NamedNodeMap attrs=book.getAttributes() System.out.println("第"+(i+1)+"本書共有"+attrs.getLength()+"個屬性") //便利book的屬性
for (int j = 0 //透過item()方法獲取book節點的某一個屬性
Node attr=attrs.item(j) //獲取屬性名
System.out.println("屬性名:"+attr.getNodeName()) //獲取屬性值
System.out.println("屬性值:"+attr.getNodeValue()) }
// //方式二,知道有且只有一個節點。並且知道屬性的名稱為“id”
// //強制型別轉換將book節點型別轉換為Element型別
// Element book =(Element) bookList.item(i) //
// //透過getAttribute(“id”)方法獲取到屬性的值
// String attrValue=book.getAttribute("id") // System.out.println("id的屬性的屬性值為"+attrValue) //解析book節點的子節點,需要用到方式一中建立的book物件
//獲取子節點的集合
NodeList childNodes=book.getChildNodes() //遍歷childNodes獲取每個子節點的節點名和節點值
System.out.println("第"+(i+1)+"本書共有"+childNodes.getLength()+"個子節點") //迴圈遍歷
for (int j = 0 //區分text型別的node和element型別的node
if(childNodes.item(j).getNodeType()==Node.ELEMENT_NODE){
//輸出了element型別節點的節點名
System.out.println("第"+(j+1)+"個節點名:"+childNodes.item(j).getNodeName()) //輸出element型別節點的節點值
//需先獲取當前節點的首個子節點,否則獲取的是《name》標籤的值NULL
//方式一:如果<name>節點下有多個子節點,此方法只輸出確定的某個子節點的值
//同樣要注意,<name>節點的第一個子節點的值是第一子節點的型別的值,還是NULL
System.out.println("節點值為:"+childNodes.item(j).getFirstChild() .getNodeValue()) //方式二:如果<name>節點下有多個子節點,此方法輸出所有子節點的text
System.out.println(childNodes.item(j).getTextContent()) }
}
System.out.println("++++++++++++結束遍歷第"+(i+1)+"本書++++++++++++") }
} catch (SAXException e) {
e.printStackTrace() } catch (IOException e) {
e.printStackTrace() }
DOMTest test=new DOMTest() test.creatXML() }
}
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
SAX方式:
使用SAX解析時建立的SAXParserHandler.
package test import java.io.File import java.io.FileNotFoundException import java.io.FileOutputStream import java.io.IOException import java.util.ArrayList import javax.xml.parsers.ParserConfigurationException import javax.xml.parsers.SAXParser import javax.xml.parsers.SAXParserFactory import javax.xml.transform.OutputKeys import javax.xml.transform.Result import javax.xml.transform.Transformer import javax.xml.transform.TransformerConfigurationException import javax.xml.transform.sax.SAXTransformerFactory import javax.xml.transform.sax.TransformerHandler import javax.xml.transform.stream.StreamResult import org.xml.sax.SAXException import org.xml.sax.helpers.AttributesImpl import test2.SAXParserHandler import test3.Book public class SAXTest {
public ArrayList<Book> parseXML(){
// 透過SAXParseFactory的靜態newInstance()
//方法獲取SAXParseFactory例項factory
SAXParserFactory factory=SAXParserFactory.newInstance() SAXParserHandler handler=null //透過SAXParserFactory例項的newSAXParser()
//方法返回SAXParse例項parser
try {
SAXParser parser= factory.newSAXParser() //建立SAXParserHandler物件
handler=new SAXParserHandler() parser.parse("books.xml", handler) System.out.println("書的數量:"+handler.getBookList().size()) for(Book book: handler.getBookList()){
System.out.println(book.getId()) System.out.println(book.getName()) System.out.println(book.getAuthor()) System.out.println(book.getPrice()) System.out.println(book.getYear()) System.out.println("-------------") }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace() } catch (ParserConfigurationException | SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
return handler.getBookList() }
public void createXML(){
ArrayList<Book> bookList=parseXML() //生成XML
//1、建立一個TransformFacroty物件
SAXTransformerFactory tff=(SAXTransformerFactory)
SAXTransformerFactory.newInstance() try {
//2、透過SAXTransformerFactory物件建立一個TransformerHandler物件
TransformerHandler handler=tff.newTransformerHandler() //3、透過handler物件建立一個Transformer物件
Transformer tr=handler.getTransformer() //4、透過Transformer物件對生成的XML檔案進行設定
//設定XML編碼
tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8") //設定換行
tr.setOutputProperty(OutputKeys.INDENT, "yes") //5、建立一個Result物件
File f=new File("src/newbooks.xml") if(!f.exists()){
f.createNewFile() }
Result result=new StreamResult(new FileOutputStream(f)) //6、建立result物件並使其與handler關聯
handler.setResult(result) //7、使用handler物件進行XML檔案的編寫
//開啟document
handler.startDocument() AttributesImpl attr=new AttributesImpl() //開始標籤
handler.startElement("", "", "bookstore", attr) for(Book book:bookList){
attr.clear() attr.addAttribute("", "", "id", "", book.getId()) handler.startElement("", "", "book", attr) attr.clear() //建立name節點
handler.startElement("", "", "name", attr) handler.characters(book.getName().toCharArray(), 0, book.getName().length()) handler.endElement("", "", "name") //建立author節點
attr.clear() handler.startElement("", "", "author", attr) handler.characters(book.getAuthor().toCharArray(), 0, book.getAuthor().length()) handler.endElement("", "", "author") //建立price節點
attr.clear() handler.startElement("", "", "price", attr) handler.characters(book.getPrice().toCharArray(), 0, book.getPrice().length()) handler.endElement("", "", "price") //建立year節點
//判斷當有此節點時才進行建立操作
if(book.getYear()!=null&&!book.getYear().trim().equals("")){
attr.clear() handler.startElement("", "", "year", attr) handler.characters(book.getYear().toCharArray(), 0, book.getYear().length()) handler.endElement("", "", "year") }
handler.endElement("", "", "book") }
//結束標籤
handler.endElement("", "", "bookstore") //關閉document
handler.endDocument() } catch (TransformerConfigurationException | IOException | SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
}
public static void main(String[] args) {
SAXTest test=new SAXTest() test.createXML() }
}
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
DOM4J方式:
RSS就是一個特殊格式的XML
package Dom4jTest import java.io.File import java.io.FileNotFoundException import java.io.FileOutputStream import java.io.IOException import java.io.UnsupportedEncodingException import java.util.Iterator import java.util.List import org.dom4j.Attribute import org.dom4j.Document import org.dom4j.DocumentException import org.dom4j.DocumentHelper import org.dom4j.Element import org.dom4j.io.OutputFormat import org.dom4j.io.SAXReader import org.dom4j.io.XMLWriter public class DOM4JTest {
public static void main(String[] args) {
new DOM4JTest().createXML() }
public void parseXML() {
// TODO Auto-generated method stub
// 建立SAXReader物件
SAXReader reader = new SAXReader() // 透過reader物件read 方法載入book.xml try {
Document document = reader.read(new File("src/res/books.xml")) // 透過document物件獲取根節點bookstore
Element bookStore = document.getRootElement() // 透過element物件的elementIterator方法獲取迭代器
Iterator it = bookStore.elementIterator() // 遍歷迭代器,獲取根節點中的資訊
while (it.hasNext()) {
System.out.println("開始遍歷一本書") Element book = (Element) it.next() // 獲取book的屬性名和屬性值
List<Attribute> bookAttrs = book.attributes() for (Attribute attr : bookAttrs) {
System.out.println("屬性名:" + attr.getName() + "\t屬性值:" + attr.getValue()) }
Iterator itt = book.elementIterator() while (itt.hasNext()) {
Element bookChild = (Element) itt.next() System.out.println("節點名:" + bookChild.getName() + "\t節點值:" + bookChild.getStringValue()) }
System.out.println("結束遍歷一本書" + "\n") }
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
}
public void createXML(){
//1、建立Document物件,代表整個XML
Document document=DocumentHelper.createDocument() //2、建立根節點
Element rss=document.addElement("rss") //3、向rss節點中新增version屬性
rss.addAttribute("version", "2.0") //4、生成子節點及內容
Element channel=rss.addElement("channel") Element title=channel.addElement("title") title.setText("新聞資訊") //設定換行
OutputFormat format=OutputFormat.createPrettyPrint() format.setEncoding("UTF-8") //5、生成XML檔案
File file=new File("rssnews.xml") XMLWriter writer try {
writer = new XMLWriter(new FileOutputStream(file),format) //設定是否轉義,預設是true進行轉義
writer.setEscapeText(false) writer.write(document) writer.close() } catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace() } catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace() }catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
}
}
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
JDOM方式:
package test import java.util.ArrayList import java.util.List import java.io.File import java.io.FileInputStream import java.io.FileNotFoundException import java.io.FileOutputStream import java.io.IOException import java.io.InputStream import java.io.InputStreamReader import org.jdom2.Attribute import org.jdom2.Document import org.jdom2.Element import org.jdom2.JDOMException import org.jdom2.input.SAXBuilder import org.jdom2.output.Format import org.jdom2.output.XMLOutputter import test3.Book public class JDOMTest {
private static ArrayList<Book> booksList = new ArrayList<Book>() public static void main(String[] args) {
new JDOMTest().createXML() }
public void parserXML() {
// JDOM解析XML檔案
// 建立一個SAXBuilder物件
SAXBuilder saxbuilder = new SAXBuilder() InputStream in try {
// 建立一個輸入流,將xml檔案載入到流中 in = new FileInputStream("src/res/books.xml") // InputStreamReader ins=new InputStreamReader(in,"UTF-8") // 透過saxbuilder的build方法將輸入流載入到saxbuilder中
Document document = saxbuilder.build(in) // 透過document物件獲取xml檔案的根節點
Element rootElement = document.getRootElement() // 獲取根節點下的子節點的集合
List<Element> bookList = rootElement.getChildren() // 使用foreach迴圈解析
for (Element book : bookList) {
Book bookEntity = new Book() System.out.println("開始解析第" + (bookList.indexOf(book) + 1) + "本書============") // 解析book的屬性
List<Attribute> attrList = book.getAttributes() // //知道節點屬性名
// book.getAttribute("id") // 針對不清楚book節點下屬性名和數量的情況
// 遍歷attrList
for (Attribute attr : attrList) {
// 獲取屬性名和屬性值
String attrName = attr.getName() String attrValue = attr.getValue() System.out.println("屬性名:" + attrName + "\t屬性值:" + attrValue) // 儲存book節點
if (attrName.equals("id")) {
bookEntity.setId(attrValue) }
}
// 對book節點的子節點的節點名和節點值進行遍歷
List<Element> bookChilds = book.getChildren() for (Element child : bookChilds) {
System.out.println("節點名:" + child.getName() + "\t節點值:" + child.getValue()) // 儲存子節點名
if (child.getName().equals("name")) {
bookEntity.setName(child.getValue()) } else if (child.getName().equals("author")) {
bookEntity.setAuthor(child.getValue()) } else if (child.getName().equals("year")) {
bookEntity.setYear(child.getValue()) } else if (child.getName().equals("price")) {
bookEntity.setPrice(child.getValue()) }
}
System.out.println("結束解析第" + (bookList.indexOf(book) + 1) + "本書============") // 新增booksList集合物件
booksList.add(bookEntity) bookEntity = null System.out.println(booksList.size()) System.out.println(booksList.get(0).getId()) System.out.println(booksList.get(0).getName()) }
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace() } catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace() } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
}
public void createXML(){
//1、生成一個根節點
Element rss=new Element("rss") rss.setAttribute("version","2.0") //2、生成一個document物件
Document document=new Document(rss) Element channel=new Element("channel") rss.addContent(channel) Element title=new Element("title") title.setText("ceshiceshi測試") channel.addContent(title) Format format=Format.getCompactFormat() format.setIndent("") format.setEncoding("GBK") //建立XMLOutputter物件
XMLOutputter outputer=new XMLOutputter(format) try {
outputer.output(document, new FileOutputStream(new File("rssnews"))) } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace() } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace() }
}
}
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
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
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
生成方式對比
DOM 基於樹結構,始終在記憶體中,方便增刪改操作
SAX基於事件
JDOM 基於底層API
DOM4J基於底層API
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31088174/viewspace-2116288/,如需轉載,請註明出處,否則將追究法律責任。