Android 中的 DefaultHandler 类不会从 xml 读取整个字符串
我正在扩展 DefaultHandler 来解析 xml。 我正在解析此页面: http://maps.googleapis .com/maps/api/directions/xml?origin=staten%20island&destination=florida&sensor=false
我正在获取所有折线>点。 除了一个特定的字符串之外,一切正常。 我像这样重写 DefaultHandler 中的字符方法:
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;
}
}
当字符串长度为 660 个字符时,长度返回 282。 这是字符串:
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@nUxXhAtoAlGzIl
>AbwAvMfRx_AnmAlr@z}@jQtTfJxJv]h]buDfqDjFrGbI~K|E~HpFnKlFfLzB|FjElMhCvI|Tw@vDnPzChPx@vFdBhOrh@xlFbNptAvAdMnB
MnEjT~EvQhFO~F
Nj CjFhEthlEbHbk@ bx@fWb^nSvXnSrYxGpKjDvGnDxHnHdR~_A|gCdNz]tEtMfs@zlBbHhQ|jDzoH|r@lzA|Yvk@xClFvJxRhInOhP\hJ|PbIvOxB|E|m@plA~LpUzs@dwAvj@hfA|D|I rDrJzlAriDhFfR~Uv~@ h
@j|Afy@{DtFzX|BtOpArLvSjcCv@dNJjEGbFDdDVnElAnIx@xDnC~JbApFb@fDbKb~@
Dj^hBvN|BbO|Dl]
这就是 DefaultHandler 返回的内容:
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
它停在字符 282 处,我不知道为什么。
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|MrF|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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 ContentHandler 接口的文档,它是由DefaultHandler实现的:
您需要在 StringBuilder 中聚合对此方法的多次调用的数据,然后在 endElement 调用中处理该数据。
From the documentation of the ContentHandler interface, which is implemented by DefaultHandler:
You need to aggregate the data from multiple calls to this method in a StringBuilder and then handle that data in the endElement call.