private void writeEscaped(char[] ch, int from, int to, boolean attribute) throws SAXException {
        int pos = from;
        while (pos < to) {
            if (ch[pos] == '<') {
                from = pos = writeCharsAndEntity(ch, from, pos, "lt");
            } else if (ch[pos] == '>') {
                from = pos = writeCharsAndEntity(ch, from, pos, "gt");
            } else if (ch[pos] == '&') {
                from = pos = writeCharsAndEntity(ch, from, pos, "amp");
            } else if (attribute && ch[pos] == '"') {
                from = pos = writeCharsAndEntity(ch, from, pos, "quot");
            } else {
                pos++;
            }
        }
        super.characters(ch, from, to - from);
    }
Writes the given characters with XML meta characters escaped.

@param ch        character array
@param from      start position in the array
@param to        end position in the array
@param attribute whether the characters should be escaped as
                 an attribute value or normal character content
@throws SAXException if the characters could not be written
tika-core/src/main/java/org/apache/tika/sax/ToXMLContentHandler.java