• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

SAX Parser

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a small program which reads a simple XML file written by me with customised tags. The problem is whenever OnCharacter method of the content handler is triggered it reads only a part of the string between the tags, but if i interchange the xml content it works fine, can anyone out tre help me out in this regard .
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no workaround - that's how SAX works. You'll need to collect the characters (maybe in a StringBuilder) until the element ends or a nested element starts.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just to add to the above post, the sax parser cannot guarantee that it has reached the end of the field.

http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html#characters(char[],%20int,%20int)

so yeah, I tend to use a stack of stringbuilders to ensure that you've reached the end of the field, and in the endElement function, pop the field. That way you ensure you have the full value.
 
reply
    Bookmark Topic Watch Topic
  • New Topic