Android XML用SAX解析无法读取“&”后的内容标记
在我的 Android 应用程序中,我读取 xml 文件并将这些数据存储在 SQLite 数据库中。 当我读取包含“&”的记录时标记它不需要整个文本。
例如,当我读取以下标签中的值时,它仅读取 49°38。另一部分是损失。
<代码><纬度> 49°38'59''N
在以下实例中,只需要获取“John Levis”部分和“&”之后的字符是损失。
<name> John Levis & sons</name>
有谁知道读取整个值吗???
这就是我从扩展 DefaultHandler 的 XML 处理程序类中获取值的方法。[此值采用 endElement 方法]
@Override
public void characters(char[] ch, int start, int length)throws SAXException
{
super.characters(ch, start, length);
if(currentElement)
{
currentValue = new String(ch, start, length);
currentElement = false;
}
}
In my android application I read xml files and store those data in SQLite database.
When I read a record that consists "&" mark it doesn't take entire text.
for example when I read the value in the following tag it only read the 49°38. The other part is loss.
<latitude> 49°38'59''N </latitude>
in the following instance it only take only get "John Levis" part and the characters after "&" are loss.
<name> John Levis & sons</name>
Does anyone have an idea to read the entire value ???
this is how I take the value from the XML handler class that extends the DefaultHandler.[this value take in the endElement methgod]
@Override
public void characters(char[] ch, int start, int length)throws SAXException
{
super.characters(ch, start, length);
if(currentElement)
{
currentValue = new String(ch, start, length);
currentElement = false;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SAX中的characters()回调允许将文本节点分割成任意多的小块。您应该累积它们并在到达文本末尾时处理它们(通常是 endElement 事件,也许是混合内容中的 startElement 事件)。许多解析器在遇到实体引用时会分割文本,但它们可以在任何地方分割文本。
The characters() callback in SAX is allowed to split a text node into as many small pieces as it likes. You should accumulate them and process them when you hit the end of the text (typically an endElement event, perhaps a startElement event in mixed content). Many parsers split the text when they hit an entity reference, but they are allowed to split it anywhere.
&应编码为 &出于 XML 的目的。您能否添加 xml 文件的标头以便我们可以看到编码?
& should be encoded as & for the purposes of xml. Could you add the header of your xml file so we can see the encoding?