Parsing XML Files with SAX
2011-06-24 14:57
344 查看
Code Source: http://www.java2s.com/Code/Java/XML/ParsingXMLFileswithSAX.htm
Anonymous inner class description: http://stackoverflow.com/questions/4216093/writing-a-class-while-instantiating-it
The anonymous inner classes is very useful in some situation. For example consider a situation where you need to create the instance of an object without creating subclass of a class and also performing additional tasks such as method overloading
Anonymous inner class description: http://stackoverflow.com/questions/4216093/writing-a-class-while-instantiating-it
The anonymous inner classes is very useful in some situation. For example consider a situation where you need to create the instance of an object without creating subclass of a class and also performing additional tasks such as method overloading
<PHONEBOOK> <PERSON> <NAME>Joe Wang</NAME> <EMAIL>joe@yourserver.com</EMAIL> <TELEPHONE>202-999-9999</TELEPHONE> <WEB>www.java2s.com</WEB> </PERSON> <PERSON> <NAME>Karol</name> <EMAIL>karol@yourserver.com</EMAIL> <TELEPHONE>306-999-9999</TELEPHONE> <WEB>www.java2s.com</WEB> </PERSON> <PERSON> <NAME>Green</NAME> <EMAIL>green@yourserver.com</EMAIL> <TELEPHONE>202-414-9999</TELEPHONE> <WEB>www.java2s.com</WEB> </PERSON> </PHONEBOOK>
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class NameLister { public static void main(String args[]) { if (args.length != 1) { System.err.println("Usage: java NameLister xmlfile.xml"); System.exit(-1); } try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { boolean name = false; public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("NAME")) { name = true; } } public void characters(char ch[], int start, int length) throws SAXException { if (name) { System.out.println("Name: " + new String(ch, start, length)); name = false; } } }; saxParser.parse(args[0], handler); } catch (Exception e) { e.printStackTrace(); } } }
相关文章推荐
- Parsing XML Files with PowerShell
- JDOM Example : Reading and Parsing XML with SAX parser in Java
- Parsing XML Files with PowerShell
- Tutorial: Loading and parsing external XML and JSON files with Unity
- Parsing XML with SAX_(MyMoviesWithHttpClient)
- Parsing XML Files(用NSXMLParser解析xml文件)
- exception http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Create XML Files Out Of SQL Server With SSIS And FOR XML Syntax
- XML processing with java (SAX)
- This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Android: Simplified source code for parsing and working with XML data and web services in Android
- HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- 关于The reference to entity "characterEncoding" must end with the ';' delimiter. org.xml.sax.SAXParseE
- jstl学习常见错误一: The absolute uri: http://java.sun.com/jst/core cannot be resolved in either web.xml or the jar files deployed with
- [转载][iPhone]XML文件解析 parsing-xml-files NSXMLParser
- XML Parsing with jQuery 【转】
- [转]Parsing Text and Binary Files With Erlang
- cannot be resolved in either web.xml or the jar files deployed with this application
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this ap
- [iPhone]XML文件解析 parsing-xml-files NSXMLParser