Created
September 7, 2014 02:29
-
-
Save SZooo/37d8d1caf1a6d5ac25ac to your computer and use it in GitHub Desktop.
sax解析
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
首先SAXParserFactory来创建一个SAXParserFactory实例 | |
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); | |
然后根据SAXParserFactory实例来创建SAXParser,再从SAXParser中得到一个XMLReader的实例,XMLReader是一个接口 | |
XMLReader xmlReader = saxParserFactory.newSAXParser().getXMLReader(); | |
把自己编写的Handler注册到XMLReader中去,一般最重要的就是ContentHandler | |
xmlReader.setContentHandler(ContentHandler); | |
| |
将XML文档或资源变成一个Java可以处理的InputStream流,解析开始 | |
xmlReader.parse(new InputSource(new StringReader(xml))); | |
这是SAX解析文档的完整的整个过程。。。。。。。。。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment