• Post Reply Bookmark Topic Watch Topic
  • New Topic

SAX Parser  RSS feed

 
manoj achari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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 .
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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.
 
Johnny Gara
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!