How to implement character method using SAXParser on Android

I am parsing xml using SAXParser and want to know if this is the correct way to implement the character method.

Suppose that there is a string variable of the element class named elementValue, and it is initialized as "" in the startElement method.

Here is the character method:

@Override
public void characters(char[] ch, int start, int length)
{
    String charsToAppend = new String(ch, start, length);
    elementValue = elementValue + charsToAppend;    
}

Is it right that we need to add to the value that we still have, and the addition is done correctly?

Also, why does the character method give an initial index? Wouldn't it be zero every time?

Thank.

+3
source share
1 answer

, , , .

, .

StringBuffer append(), :

public void characters(char[] ch, int start, int length) {
  yourStringBuffer.append(ch, start, length);
}
+9

Source: https://habr.com/ru/post/1731914/


All Articles