private static void includeFile(FileWrapper currentFolder, Element currentElement) throws IOException {
        NodeList list = currentElement.getElementsByTagNameNS(XmlPreProcessor.preprocessNamespaceUri, "include");
        while (list.getLength() > 0) {
            Element elem = (Element) list.item(0);
            Element parent = (Element) elem.getParentNode();
            String filename = elem.getAttribute("file");
            boolean required = ! elem.hasAttribute("required") || Boolean.parseBoolean(elem.getAttribute("required"));
            FileWrapper file = currentFolder.child(filename);

            Document subFile = IncludeProcessor.parseIncludeFile(file, parent.getTagName(), required);
            includeFile(file.parent().orElseThrow(() -> new NoSuchElementException(file + " has no parent")),
                        subFile.getDocumentElement());

            //System.out.println("document before merging: " + documentAsString(doc));
            IncludeProcessor.mergeInto(parent, XML.getChildren(subFile.getDocumentElement()));
            //System.out.println("document after merging: " + documentAsString(doc));
            parent.removeChild(elem);
            //System.out.println("document after removing child: " + documentAsString(doc));
            list = currentElement.getElementsByTagNameNS(XmlPreProcessor.preprocessNamespaceUri, "include");
        }
    }
Handles preprocess:include statements and returns a Document which has all the include statements resolved

@author hmusum
config-application-package/src/main/java/com/yahoo/config/application/IncludeProcessor.java