@Override
    public void startElement(String uri, String localName, String name, Attributes atts)
            throws SAXException {
        // TODO: enable this, but some parsers currently
        // trip it
        //assert verifyStartElement(name);
        // Look for any invalid characters in attribute values.
        for (int i = 0; i < atts.getLength(); i++) {
            if (isInvalid(atts.getValue(i))) {
                // Found an invalid character, so need to filter the attributes
                AttributesImpl filtered = new AttributesImpl();
                for (int j = 0; j < atts.getLength(); j++) {
                    String value = atts.getValue(j);
                    if (j >= i && isInvalid(value)) {
                        // Filter the attribute value when needed
                        Output buffer = new StringOutput();
                        filter(value.toCharArray(), 0, value.length(), buffer);
                        value = buffer.toString();
                    }
                    filtered.addAttribute(atts.getURI(j), atts.getLocalName(j), atts.getQName(j),
                            atts.getType(j), value);
                }
                atts = filtered;
                break;
            }
        }
        super.startElement(uri, localName, name, atts);
    }
Outputs the replacement for an invalid character. Subclasses can
override this method to use a custom replacement.

@param output where the replacement is written to
@throws SAXException if the replacement could not be written
tika-core/src/main/java/org/apache/tika/sax/SafeContentHandler.java