in log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/XmlWriter.java [64:105]
public static String toString(final String rootElementName, final BiConsumer<Document, Element> documentConsumer) {
try {
// Create the document
final DocumentBuilderFactory documentBuilderFactory = XmlUtils.createDocumentBuilderFactory();
final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
// Append the license comment
final Document document = documentBuilder.newDocument();
document.setXmlStandalone(true);
final Comment licenseComment = document.createComment(LS +
" ~ Licensed to the Apache Software Foundation (ASF) under one or more" + LS +
" ~ contributor license agreements. See the NOTICE file distributed with" + LS +
" ~ this work for additional information regarding copyright ownership." + LS +
" ~ The ASF licenses this file to you under the Apache License, Version 2.0" + LS +
" ~ (the \"License\"); you may not use this file except in compliance with" + LS +
" ~ the License. You may obtain a copy of the License at" + LS +
" ~" + LS +
" ~ http://www.apache.org/licenses/LICENSE-2.0" + LS +
" ~" + LS +
" ~ Unless required by applicable law or agreed to in writing, software" + LS +
" ~ distributed under the License is distributed on an \"AS IS\" BASIS," + LS +
" ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." + LS +
" ~ See the License for the specific language governing permissions and" + LS +
" ~ limitations under the License." + LS +
" ");
document.appendChild(licenseComment);
// Create the root element
final Element rootElement = document.createElement(rootElementName);
document.appendChild(rootElement);
// Apply requested changes
documentConsumer.accept(document, rootElement);
// Serialize the document
return serializeXmlDocument(document, rootElementName);
} catch (final Exception error) {
throw new RuntimeException("failed writing XML", error);
}
}