Skip to content

Instantly share code, notes, and snippets.

@Goddard
Created June 28, 2012 04:31
Show Gist options
  • Select an option

  • Save Goddard/3009075 to your computer and use it in GitHub Desktop.

Select an option

Save Goddard/3009075 to your computer and use it in GitHub Desktop.
XML Sax
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