Created
June 28, 2012 04:31
-
-
Save Goddard/3009075 to your computer and use it in GitHub Desktop.
XML Sax
This file contains hidden or 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
| import java.net.URL; | |
| import javax.xml.parsers.SAXParser; | |
| import javax.xml.parsers.SAXParserFactory; | |
| import org.xml.sax.InputSource; | |
| /** | |
| * | |
| * @author goddard | |
| */ | |
| public class XMLReader | |
| { | |
| public void XMLReader(URL url) | |
| { | |
| try | |
| { | |
| /* Get a SAXParser from the SAXPArserFactory. */ | |
| SAXParserFactory spf = SAXParserFactory.newInstance(); | |
| SAXParser sp = spf.newSAXParser(); | |
| /* Get the XMLReader of the SAXParser we created. */ | |
| XMLReader xr = sp.getXMLReader(); | |
| /* Create a new ContentHandler and apply it to the XML-Reader*/ | |
| ExampleHandler myExampleHandler = new ExampleHandler(); | |
| xr.setContentHandler(myExampleHandler); | |
| /* Parse the xml-data from our URL. */ | |
| xr.parse(new InputSource(url.openStream())); | |
| /* Parsing has finished. */ | |
| /* Our ExampleHandler now provides the parsed data to us. */ | |
| InsuranceDataObject parsedExampleDataSet = myExampleHandler.getParsedData(); | |
| } | |
| catch(Exception e) | |
| { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment