DefaultHandler class in android doesnt read entire string from xml
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@vACdM
WnnBjeEtI|PlIxNxHhMjLdQ|dAlwA~CxfEfOxRlK
O~PdUvOlTnHdJbYl\fVlWq@~p@~gA
gAfKzKbPRpa@bi@|wAnuBjZ|c@rD~F
JjP|I|Qzr@~AbKpS
J~OvGdKnPhUbMpN~{@~{@tLhMlZfZnI~Ilh@nh@nNO~GbJjEpGpErHbIfPpDxIvDpKzRvp@rE|M开发者_如何学PythonrF|MhKpRbF
Ir_@jo@LtS~MzYp[bw@hEvJ|F
LbLvQzHrJfv@fz@nUxXhAtoAlGzIl
AbwAvMfRx_AnmAlr@z}@jQtTfJxJv]h]buDfqDjFrGbI~K|E~HpFnKlFfLzB|FjElMhCvI|Tw@vDnPzChPx@vFdBhOrh@xlFbNptAvAdMnB
MnEjT~EvQhFO~F
NjCjFhEtHlEbHbk@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@vACdM
WnnBjeEtI|PlIxNxHhMjLdQ|dAlwA~CxfEfOxRlK
O~PdUvOlTnHdJbYl\fVlWq@~p@~gA
gAfKzKbPRpa@bi@|wAnuBjZ|c@rD~F
JjP|I|Qzr@~AbKpS
J~OvGdKnPhUbMpN~{@~{@tLhMlZfZnI~Ilh@nh@nNO~GbJjEpGpErHbIfPpDxIvDpKzRvp@rE|MrF|MhKpRbF
Ir_@jo@LtS~MzYp[bw@hEvJ|F
LbLvQzHrJfv@fz@nUxXh`Ato
It stops at character 282 and I don't know why.
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.
精彩评论