Coyttl
Coyttl

Reputation: 534

XmlPullParser skipping START_TAG?

So I'm trying to parse a GPX file using the XmlPullParser. For the most part, I have it working, but noticed that I'm not getting what I'm expecting. A snippet of the file:

<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1">
 <wpt lat="34.767778" lon="-88.078889">
  <name>EG1325</name>
  <type>Waypoint</type>
  <extensions>
  <groundspeak:cache>
   <groundspeak:country>United States</groundspeak:country>
</groundspeak:cache>
   </extensions>
</wpt>
</gpx>

I trimmed the unimportant tags here, for the purpose of this question, assuming that the file passes validation with all namespaces represented. (Because the full file does.)

The issue comes when I get past the <type> tag. Using EITHER next() or nextToken(), I will get the END_TAG event for the <type> tag. Then my next event will be a TEXT event, an the text will contain \n. The event after that will be the START_TAG, but for the <groundspeak:cache> and NOT the <extensions> tag.

I seem to get this both for using the nextToken() and next() calls. Is this expected?

Edit to add: The only setting I am setting in code for the XmlPullParser is:

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);

Upvotes: 0

Views: 34

Answers (1)

KyluAce
KyluAce

Reputation: 1000

Check your xml file. Some xml files contains at start some extra bytes, to be specific "EF BB BF". It's called BOM (Byte-Order-Mark). When xml contains this extra bytes our XmlPullParser doesn't work properly and behave like there is no START_TAG event and goes to END_DOCUMENT.

Upvotes: 1

Related Questions