首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

java读取xml资料的四种方法【转】

2012-10-06 
java读取xml文件的四种方法【转】Xml代码?Java代码?Java代码?Java代码?Java代码?import?javax.xml.parsers.S

java读取xml文件的四种方法【转】

Xml代码?java读取xml资料的四种方法【转】
  1. Java代码?java读取xml资料的四种方法【转】
    1. Java代码?java读取xml资料的四种方法【转】
      1. Java代码?java读取xml资料的四种方法【转】
        1. Java代码?java读取xml资料的四种方法【转】
          1. import?javax.xml.parsers.SAXParser; ??
          2. import?javax.xml.parsers.SAXParserFactory; ??
          3. ??
          4. import?org.xml.sax.Attributes; ??
          5. import?org.xml.sax.InputSource; ??
          6. import?org.xml.sax.SAXException; ??
          7. import?org.xml.sax.helpers.DefaultHandler; ??
          8. ??
          9. public?class?MyXMLReader2SAX?extends?DefaultHandler { ??
          10. ??
          11. java.util.Stack tags =?new?java.util.Stack(); ??
          12. ??
          13. public?MyXMLReader2SAX() { ??
          14. ??super(); ??
          15. } ??
          16. ??
          17. public?static?void?main(String args[]) { ??
          18. ??long?lasting = System.currentTimeMillis(); ??
          19. ??try?{ ??
          20. ??? SAXParserFactory sf = SAXParserFactory.newInstance(); ??
          21. ??? SAXParser sp = sf.newSAXParser(); ??
          22. ??? MyXMLReader2SAX reader =?new?MyXMLReader2SAX(); ??
          23. ??? sp.parse(new?InputSource("data_10k.xml"), reader); ??
          24. ?? }?catch?(Exception e) { ??
          25. ??? e.printStackTrace(); ??
          26. ?? } ??
          27. ??
          28. ?? System.out.println("运行时间:"?+ (System.currentTimeMillis() - lasting) ??
          29. ???? +?"毫秒"); ??
          30. } ??
          31. ??
          32. public?void?characters(char?ch[],?int?start,?int?length) ??
          33. ???throws?SAXException { ??
          34. ?? String tag = (String) tags.peek(); ??
          35. ??if?(tag.equals("NO")) { ??
          36. ??? System.out.print("车牌号码:"?+?new?String(ch, start, length)); ??
          37. ?? } ??
          38. ??if?(tag.equals("ADDR")) { ??
          39. ??? System.out.println("地址:"?+?new?String(ch, start, length)); ??
          40. ?? } ??
          41. } ??
          42. ??
          43. public?void?startElement(String uri, String localName, String qName, ??
          44. ??? Attributes attrs) { ??
          45. ?? tags.push(qName); ??
          46. } ??
          47. }??
          来自:?http://hi.baidu.com/zhangyadong110/blog/item/d1258010346b9519b8127b0b.html