日期:2014-05-20 浏览次数:21086 次
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new FileInputStream("C:\\q.xml")); Element e = doc.getDocumentElement(); printChildNodes(e.getChildNodes()); } public static void printChildNodes(NodeList list) { for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); System.out.println(n.getNodeName() + " : " + n.getNodeValue()); printChildNodes(n.getChildNodes()); } }