Results 1 to 2 of 2

Thread: SAX Parse

  1. #1
    bluefloyd8 is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default 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).

    Java 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);
                [b]fin = new FileReader(filename);
                xr.parse(new InputSource(fin));[/b]
    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:
    Java Code:
    xr.parse(new InputSource(url.openStream()));
    Thanks for the help!

  2. #2
    jelly's Avatar
    jelly is offline Member
    Join Date
    Jan 2008
    Location
    Somerset, UK
    Posts
    46
    Rep Power
    0

    Default

    You haven't said what the problem is that you are getting :) However InputSources expect to work with Streams rather than Readers so I would change your bold portion to read:
    Java Code:
    fin = new FileInputStream(filename);
     xr.parse(new InputSource(fin));
    and of course change the definition of fin to be a FileInputStream
    -- Hope that helps

Similar Threads

  1. how to Parse int to a string variable (pls hlp)
    By raj reddy in forum Threads and Synchronization
    Replies: 5
    Last Post: 06-10-2008, 06:32 AM
  2. how to parse an xml file
    By oregon in forum XML
    Replies: 3
    Last Post: 08-01-2007, 04:53 PM
  3. How to parse in html
    By paty in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 12:29 AM
  4. Parse error
    By Eric in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 06:32 PM
  5. How to parse HTML tags
    By Ada in forum Advanced Java
    Replies: 1
    Last Post: 05-31-2007, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •