1

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&#039;59&#039;&#039;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;
    }
}
JibW
  • 4,538
  • 17
  • 66
  • 101

2 Answers2

1

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.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

& should be encoded as &amp; for the purposes of xml. Could you add the header of your xml file so we can see the encoding?

Craig Millard
  • 225
  • 1
  • 2
  • 8