src/main/java/com/cloudbees/jenkins/support/configfiles/SecretHandler.java
public static String findSecrets(File xmlFile) throws SAXException, IOException, TransformerException {

        XMLReader xr = new XMLFilterImpl(XMLReaderFactory.createXMLReader()) {
            private String tagName = "";

            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts)
                    throws SAXException {
                tagName = qName;
                super.startElement(uri, localName, qName, atts);
            }

            public void endElement(String uri, String localName, String qName) throws SAXException {
                tagName = "";
                super.endElement(uri, localName, qName);
            }

            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                if (!"".equals(tagName)) {
                    String value = new String(ch, start, length).trim();
                    //if it's a secret, then use a place holder
                    // convenience check !"{}".equals(value) because of JENKINS-47500
                    if (!"".equals(value) && !"{}".equals(value)) {
                        if ((Secret.decrypt(value)) != null || SecretBytes.isSecretBytes(value)) {
                            ch = SECRET_MARKER.toCharArray();
                            start = 0;
                            length = ch.length;
                        }
                    }
                }
                super.characters(ch, start, length);
            }
        };
        String str = FileUtils.readFileToString(xmlFile);
        Source src = createSafeSource(xr, new InputSource(new StringReader(str)));
        final ByteArrayOutputStream result = new ByteArrayOutputStream();
        Result res = new StreamResult(result);
        TransformerFactory factory = TransformerFactory.newInstance();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        Transformer transformer = factory.newTransformer();
        //omit xml declaration because of https://bugs.openjdk.java.net/browse/JDK-8035437
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, OUTPUT_ENCODING);

        try {
            transformer.transform(src, res);
            return result.toString("UTF-8");
        } catch (TransformerException e) {
            if (ENABLE_FALLBACK) {
                return findSecretFallback(str);
            } else {
                throw e;
            }
        }
    }
/**
     * find the secret in the xml file and replace it with the place holder
     * @param xmlFile we want to parse
     * @return the patched xml content with redacted secrets
     * @throws SAXException if some XML parsing issue occurs.
     * @throws IOException if some issue occurs while reading the providing file.
     * @throws TransformerException if an issue occurs while writing the result.
     */
find the secret in the xml file and replace it with the place holder
@param xmlFile we want to parse
@return the patched xml content with redacted secrets
@throws SAXException if some XML parsing issue occurs.
@throws IOException if some issue occurs while reading the providing file.
@throws TransformerException if an issue occurs while writing the result.
find the secret in the xml file and replace it with the place holder @param xmlFile we want to parse @return the patched xml content with redacted secrets @throws SAXException if some XML parsing issue occurs . @throws IOException if some issue occurs while reading the providing file . @throws TransformerException if an issue occurs while writing the result .
public static String findSecrets(File xmlFile) throws SAXException, IOException, TransformerException {
        XMLReader xr = new XMLFilterImpl(XMLReaderFactory.createXMLReader()) {
            private String tagName = "";
            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts)
                    throws SAXException {
                tagName = qName;
                super.startElement(uri, localName, qName, atts);
            }
            public void endElement(String uri, String localName, String qName) throws SAXException {
                tagName = "";
                super.endElement(uri, localName, qName);
            }
            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                if (!"".equals(tagName)) {
                    String value = new String(ch, start, length).trim();
                    if (!"".equals(value) && !"{}".equals(value)) {
                        if ((Secret.decrypt(value)) != null || SecretBytes.isSecretBytes(value)) {
                            ch = SECRET_MARKER.toCharArray();
                            start = 0;
                            length = ch.length;
                        }
                    }
                }
                super.characters(ch, start, length);
            }
        };
        String str = FileUtils.readFileToString(xmlFile);
        Source src = createSafeSource(xr, new InputSource(new StringReader(str)));
        final ByteArrayOutputStream result = new ByteArrayOutputStream();
        Result res = new StreamResult(result);
        TransformerFactory factory = TransformerFactory.newInstance();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, OUTPUT_ENCODING);
        try {
            transformer.transform(src, res);
            return result.toString("UTF-8");
        } catch (TransformerException e) {
            if (ENABLE_FALLBACK) {
                return findSecretFallback(str);
            } else {
                throw e;
            }
        }
    }
public static String findSecrets ( File xmlFile ) throws SAXException , IOException , TransformerException { XMLReader xr = new XMLFilterImpl ( XMLReaderFactory . createXMLReader ( ) ) { private String tagName = "" ; @ Override public void startElement ( String uri , String localName , String qName , Attributes atts ) throws SAXException { tagName = qName ; super . startElement ( uri , localName , qName , atts ) ; } public void endElement ( String uri , String localName , String qName ) throws SAXException { tagName = "" ; super . endElement ( uri , localName , qName ) ; } @ Override public void characters ( char [ ] ch , int start , int length ) throws SAXException { if ( ! "" . equals ( tagName ) ) { String value = new String ( ch , start , length ) . trim ( ) ; if ( ! "" . equals ( value ) && ! "{}" . equals ( value ) ) { if ( ( Secret . decrypt ( value ) ) != null || SecretBytes . isSecretBytes ( value ) ) { ch = SECRET_MARKER . toCharArray ( ) ; start = 0 ; length = ch . length ; } } } super . characters ( ch , start , length ) ; } } ; String str = FileUtils . readFileToString ( xmlFile ) ; Source src = createSafeSource ( xr , new InputSource ( new StringReader ( str ) ) ) ; final ByteArrayOutputStream result = new ByteArrayOutputStream ( ) ; Result res = new StreamResult ( result ) ; TransformerFactory factory = TransformerFactory . newInstance ( ) ; factory . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; Transformer transformer = factory . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , "yes" ) ; transformer . setOutputProperty ( OutputKeys . ENCODING , OUTPUT_ENCODING ) ; try { transformer . transform ( src , res ) ; return result . toString ( "UTF-8" ) ; } catch ( TransformerException e ) { if ( ENABLE_FALLBACK ) { return findSecretFallback ( str ) ; } else { throw e ; } } }
find the secret in the xml file and replace it with the place holder
 @param xmlFile we want to parse
 @return the patched xml content with redacted secrets
 @throws SAXException if some XML parsing issue occurs.
find the secret in the xml file and replace it with the place holder @param xmlFile we want to parse @return the patched xml content with redacted secrets @throws SAXException if some XML parsing issue occurs .
//if it's a secret, then use a place holder // convenience check !"{}".equals(value) because of JENKINS-47500 //omit xml declaration because of https://bugs.openjdk.java.net/browse/JDK-8035437