Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to stop parsing of a file with SAX

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
This is the code I have

Need just to stop parsing the document.
I tried so many options but I am stuck.
Can someone help?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just throw an exception - it is by far the simplest thing to do. You might make that a custom extension of java.lang.RuntimeException and specifically catch that exception in the code that starts the parser - that way you can conveniently package the information found.

HOWEVER - I must point out a serious bug in your code. You simply can not rely on the characters method being called with the complete text to create a Date. It might work fine for some random amount of time and then fail.
Depending on how the buffer loads that the SAX parser is reading fall in the stream of text, characters may get only part of the element contents.

Instead - when the startElement for the date is hit, begin accumulating characters input in a StringBuffer. When the endElement is hit you can look at the complete element contents.

Bill
 
Branko Santo
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I bow down to thee

Thanks a lot man!
 
Branko Santo
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you once again William
I got something like this now.
This should work?

 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you are on the right track to me but instead of a StringWriter you could use a StringBuilder(in Java 1.5 - slightly faster) or StringBuffer(in earlier Java).

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic