Thread: SAX Parse
View Single Post
  #1 (permalink)  
Old 01-22-2008, 08:35 PM
bluefloyd8 bluefloyd8 is offline
Member
 
Join Date: Jan 2008
Posts: 4
bluefloyd8 is on a distinguished road
SAX Parse
Hello!
Ive successfully written code to parse a XML file from an internet URL. Now Im trying to do the same thing to a local file and im missing something simple (i think).

Code:
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); fin = new FileReader(filename); xr.parse(new InputSource(fin));
fin is declared as a FileReader object and initialized to null. When I parsed a file from the internet, I used the following code instead of the code in bold above:
Code:
xr.parse(new InputSource(url.openStream()));
Thanks for the help!
Reply With Quote
Sponsored Links