ohana
ohana

Reputation: 285

SAXParser how to ignore white space in element text

i have SAXParser to parse xml feed, for some element there are whitespace characters embedded like

 <category>Beauty, Spas, & Salons</category>

and the parser only extract 'Beauty' from 'category' instead of 'Beauty, Spas, & Salons', how can i force it to extract the whole string? thanks

Upvotes: 1

Views: 2535

Answers (1)

antlersoft
antlersoft

Reputation: 14751

The parser is almost certainly giving you the whole string but it is over multiple calls to characters(). characters() will be called any number of times to deliver the contents of an element; it could be one character at a time. You need to keep a String (or StringBuilder...) and add to it each time characters() is called. You don't know you have the whole element content until endElement() is called.

Upvotes: 7

Related Questions