private static void addEncodingDetectors(Mode mode, Element rootElement, Document doc,
                                             TikaConfig config) throws Exception {
        EncodingDetector encDetector = config.getEncodingDetector();

        if (mode == Mode.MINIMAL && encDetector instanceof DefaultEncodingDetector) {
            // Don't output anything, all using defaults
            Node detComment = doc.createComment(
                    "for example: <encodingDetectors><encodingDetector class=\"" +
                            "org.apache.tika.detect.DefaultEncodingDetector\">" +
                            "</encodingDetectors>");
            rootElement.appendChild(detComment);
            return;
        }

        Element encDetectorsElement = doc.createElement("encodingDetectors");
        if (mode == Mode.CURRENT && encDetector instanceof DefaultEncodingDetector ||
                !(encDetector instanceof CompositeEncodingDetector)) {
            Element encDetectorElement = doc.createElement("encodingDetector");
            encDetectorElement.setAttribute("class", encDetector.getClass().getCanonicalName());
            encDetectorsElement.appendChild(encDetectorElement);
        } else {
            List<EncodingDetector> children =
                    ((CompositeEncodingDetector) encDetector).getDetectors();
            for (EncodingDetector d : children) {
                Element encDetectorElement = doc.createElement("encodingDetector");
                encDetectorElement.setAttribute("class", d.getClass().getCanonicalName());
                serializeParams(doc, encDetectorElement, d);

                encDetectorsElement.appendChild(encDetectorElement);
            }
        }
        rootElement.appendChild(encDetectorsElement);
    }
@param config  config to serialize
@param mode    serialization mode
@param writer  writer
@param charset charset
@throws Exception
tika-core/src/main/java/org/apache/tika/config/TikaConfigSerializer.java