Question

I am extending DefaultHandler to parse an xml. I am parsing this page: http://maps.googleapis.com/maps/api/directions/xml?origin=staten%20island&destination=florida&sensor=false

I am getting all the polyline>points. Everything works fine except for one specific string. I am overriding the characters method in DefaultHandler like this:

public void characters(char[] ch, int start, int length) throws SAXException {
if (currentElement) {
    Log.v("Length", length+"");
    currentValue = new String(ch, start, length);
    currentElement = false;
    }

}

The length returns 282 when the string is 660 characters long. This is the string:

qhitFxpifMn@t@vACdMWnnBjeEtI|PlIxNxHhMjLdQ|dAlwA~CxfEfOxRlKO~PdUvOlTnHdJbYl\fVlWq@~p@~gAgAfKzKbPRpa@bi@|wAnuBjZ|c@rD~FJjP|I|Qzr@~AbKpSJ~OvGdKnPhUbMpN~{@~{@tLhMlZfZnI~Ilh@nh@nNO~GbJjEpGpErHbIfPpDxIvDpKzRvp@rE|MrF|MhKpRbFIr_@jo@LtS~MzYp[bw@hEvJ|FLbLvQzHrJfv@fz@nUxXhAtoAlGzIlAbwAvMfRx_AnmAlr@z}@jQtTfJxJv]h]buDfqDjFrGbI~K|E~HpFnKlFfLzB|FjElMhCvI|Tw@vDnPzChPx@vFdBhOrh@xlFbNptAvAdMnBMnEjT~EvQhFO~FNjCjFhEtHlEbHbk@bx@fWb^nSvXnSrYxGpKjDvGnDxHnHdR~_A|gCdNz]tEtMfs@zlBbHhQ|jDzoH|r@lzA|Yvk@xClFvJxRhInOhP\hJ|PbIvOxB|E|m@plA~LpUzs@dwAvj@hfA|D|IrDrJzlAriDhFfR~Uv~@h@j|Afy@{DtFzX|BtOpArLvSjcCv@dNJjEGbFDdDVnElAnIx@xDnC~JbApFb@fDbKb~@Dj^hBvN|BbO|Dl]

And this is what DefaultHandler returns:

qhitFxpifMn@t@vACdMWnnBjeEtI|PlIxNxHhMjLdQ|dAlwA~CxfEfOxRlKO~PdUvOlTnHdJbYl\fVlWq@~p@~gAgAfKzKbPRpa@bi@|wAnuBjZ|c@rD~FJjP|I|Qzr@~AbKpSJ~OvGdKnPhUbMpN~{@~{@tLhMlZfZnI~Ilh@nh@nNO~GbJjEpGpErHbIfPpDxIvDpKzRvp@rE|MrF|MhKpRbFIr_@jo@LtS~MzYp[bw@hEvJ|FLbLvQzHrJfv@fz@nUxXh`Ato

It stops at character 282 and I don't know why.

Was it helpful?

Solution

From the documentation of the ContentHandler interface, which is implemented by DefaultHandler:

SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks

You need to aggregate the data from multiple calls to this method in a StringBuilder and then handle that data in the endElement call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top