Search code examples
javaandroidxmlxml-parsingxmlpullparser

Make XmlPullParser ignore whitespace?


I am parsing Xml with an XmlPullParser. I just want to deal with the Xml tags and the text contained within them however, the XmlPullParser reads in the whitespace text (spaces and carriage returns) between tags. Can it be set to ignore this whitespace?


Solution

  • I've not used XmlPullParser before (so apologies if this is totally wrong) but having a glance at the javadocs, it seems like when you call nextToken() you'll have to look at the return value and skip over IGNORABLE_WHITESPACE .

    The following was inappropriate (thanks Jeff): BTW are you being forced to use XmlPullParser? Based on what it sounds like you're trying to achieve, I'd consider a higher level API like Simple. I generally use JAXB, but that's not by choice haha.