DOM解析器
2015-08-03 21:00
309 查看
package com.DOM;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.do
9bfc
m.Node;
import org.xml.sax.SAXException;
public class DomTest {
}
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.do
9bfc
m.Node;
import org.xml.sax.SAXException;
public class DomTest {
public static void main(String[] args) { // TODO Auto-generated method stub DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder();//创建DOM的解析工厂 Document document = builder.parse("d:\\11.txt");//使用解析器解析文档生成倒树的Document NodeList list = document.getElementsByTagName("Weather");//得到文档中的所有Weather标签 Node node = list.item(0);//得到第一个Weather Node child = node.getFirstChild();//得到weather的第一个子标签city Node next = child.getNextSibling();//得到city的下一个标签 while (next != null) {//判断有没有走到最后一个标签 if (next.getNodeType() == node.ELEMENT_NODE) {//判断节点类型是ELEMENT_NODE Node content = next.getFirstChild();//得到该节点的第一个子节点不能为空 if (content != null) { System.out.println(next.getFirstChild().getNodeValue().trim()); } } next=next.getNextSibling();//得到下一个标签 } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
}
相关文章推荐
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- Linux stat 命令
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 线性探测法构造哈希表(hash)
- 随笔
- 第76讲:模式匹配下的赋值语句
- BFS(两点搜索) FZOJ 2150 Fire Game