Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-22-2008, 07:35 PM
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!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-25-2008, 04:57 PM
jelly's Avatar
Member
 
Join Date: Jan 2008
Location: Somerset, UK
Posts: 46
jelly is on a distinguished road
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:
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +3. The time now is 04:57 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org