Posts

Showing posts from August, 2016

SAX xml parser and Java

Image
Summary In this article i want to show - an introduction to sax - a simple use case that dimostrate the basic functionality of SAX - how to validate an xml document with SAX - how to use the filters Introduction to SAX SAX (Simple API for XML) is an xml parser. It started as java api but then it becames a standard. Since SAX is a standard, there are a several implementations (in java and other languages). Java also provides a unified interface to the parsers (so also to SAX) through JAXP (java api for xml processing). Basically JAXP uses the factory pattern to access a parser like SAX and then for parse the xml document. So to parse an xml document we need an XMLReader and we can have this by retrieve the sax factory and then a sax parser object. Something like this SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser saxParser = spf.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.parse("/path/to/people.xml")...