class DOMParserUtil {

    public static Map<Node, Node> createNestedNodes(Document document, String mainContainerNodeName, String containerNodeName, String childNodeName, String nodeContent) {
        Map<Node, Node> toReturn = new HashMap<>();
        asStream(document.getElementsByTagName(mainContainerNodeName))
                .map(Node::getChildNodes)
                .forEach(containerNodeList ->
                                 asStream(containerNodeList)
                                         .filter(containerNode -> Objects.equals(containerNodeName, containerNode.getNodeName()))
                                         .forEach(containerNode -> {
                                             Node childNode = document.createElement(childNodeName);
                                             containerNode.appendChild(childNode);
                                             if (nodeContent != null) {
                                                 childNode.setTextContent(nodeContent);
                                             }
                                             toReturn.put(containerNode, childNode);
                                         }));
        return toReturn;
    }

    private  DOMParserUtil();

}