88. throws SAXException {
89. String tag = (String) tags.peek(); 90. if (tag.equals(\
91. System.out.println(\
tart, length)); 92. }
93. if (tag.equals(\
94. System.out.println(\
tart, length)); 95. }
96. System.out.println(\--------------\97. } 98.
99. /**
100. * JDOM方式 101. * @since V2.0
102. * @author David.Wei 103. * @date 2008-4-11 104. * @return void 105. */
106. public void JDOM() {
107. long lasting = System.currentTimeMillis(); 108. try {
109. SAXBuilder builder = new SAXBuilder(); 110. org.jdom.Document doc = builder.build(new File
(\
111. Element foo = doc.getRootElement(); 112. List allChildren = foo.getChildren();
113. for (int i = 0; i < allChildren.size(); i++) {
114. System.out.println(\
115. + ((Element) allChildren.get(i)).g
etChild(\
116. .getText()); 117. System.out.println(\
118. + ((Element) allChildren.get(i)).g
etChild(\
119. .getText());
120. System.out.println(\---------------------------\121. } catch (Exception e) { 122. e.printStackTrace(); 123. }
124. System.out.println(\:\
125. + (System.currentTimeMillis() - lasting) +
\126. } 127.
128. /**
129. * DOM4J方式 130. * @since V2.0
131. * @author David.Wei 132. * @date 2008-4-11 133. * @return void 134. */
135. public void DOM4J() {
136. long lasting = System.currentTimeMillis(); 137. try {
138. File f = new File(\139. SAXReader reader = new SAXReader();
140. org.dom4j.Document doc = reader.read(f); 141. org.dom4j.Element root = doc.getRootElement();
142. org.dom4j.Element foo;
143. for (Iterator i = root.elementIterator(\
; i.hasNext();) {
144. foo = (org.dom4j.Element) i.next(); 145. System.out.println(\
mentText(\
146. System.out.println(\
mentText(\
147. System.out.println(\---------------------------\148. }
149. } catch (Exception e) { 150. e.printStackTrace(); 151. }
152. System.out.println(\:\
153. + (System.currentTimeMillis() - lasting) +
\154. } 155.
156. public static void main(String arge[]) { 157. MyXMLReader myXML = new MyXMLReader();
158. System.out.println(\
===================\159. myXML.DOM();
160. System.out.println(\
===================\161. myXML.SAX();
162. System.out.println(\
===================\163. myXML.JDOM();
164. System.out.println(\
===================\
165. myXML.DOM4J();
166. System.out.println(\
===================\167. } 168. }
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库xml解析的四种方式(2)在线全文阅读。
相关推荐: