private static void editXMLFile(Path XMLPath, String tagId, String tagName,
      String replacementTagName, String parentTagName, HashMap<String, String> attributes,
      boolean writeOnSimilarAttributeNames) {

    try {
      // Get XML file to edit
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
      Document doc = docBuilder.parse(XMLPath.toFile());

      Node node = null;
      // Get node with specified tagId
      if (tagId != null) {
        node = findNodeWithAttribute(doc, tagName, "id", tagId);
      }
      // If writing on similar attributes then search by tag name
      else if (writeOnSimilarAttributeNames) {
        // Get all the nodes with the given tag name
        NodeList nodes = doc.getElementsByTagName(tagName);
        for (int i = 0; i < nodes.getLength(); i++) {
          Node n = nodes.item(i);
          // If the node being iterated across has the exact attributes then it is the one that
          // should be edited
          if (nodeHasExactAttributes(n, attributes, false)) {
            node = n;
            break;
          }
        }
      }
      // If a node if found
      if (node != null) {
        doc.renameNode(node, null, replacementTagName);
        // Rewrite the node attributes
        rewriteNodeAttributes(node, attributes);
        // Write the tagId so that it can be found easier next time
        if (tagId != null) {
          ((Element) node).setAttribute("id", tagId);
        }
      }
      // No node found creates new element under the parent tag passed in
      else {
        Element e = doc.createElement(replacementTagName);
        // Set id attribute
        if (tagId != null) {
          e.setAttribute("id", tagId);
        }
        // Set other attributes
        for (String key : attributes.keySet()) {
          e.setAttribute(key, attributes.get(key));
        }

        // Add it as a child of the tag for the file
        doc.getElementsByTagName(parentTagName).item(0).appendChild(e);
      }

      // Write updated XML file
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      DOMSource source = new DOMSource(doc);
      StreamResult result = new StreamResult(XMLPath.toFile());
      transformer.transform(source, result);

      logger.info("Modified container XML file " + XMLPath);
    } catch (Exception e) {
      throw new RuntimeException("Unable to edit XML file " + XMLPath, e);
    }
  }
Edit the given xml file

Uses {@link #findNodeWithAttribute(Document, String, String, String)},
{@link #rewriteNodeAttributes(Node, HashMap)},
{@link #nodeHasExactAttributes(Node, HashMap, boolean)} to edit the required parts of the XML
file.

@param XMLPath The path to the xml file to edit
@param tagId The id of tag to edit. If null, then this method will add a new xml element,
       unless writeOnSimilarAttributeNames is set to true.
@param tagName The name of the xml element to edit
@param replacementTagName The new name of the XML attribute that is being edited
@param parentTagName The parent element of the element we should edit
@param attributes the xml attributes for the element to edit
@param writeOnSimilarAttributeNames If true, find an existing element with the same set of
       attributes as the attributes parameter, and modifies the attributes of that element,
       rather than adding a new element. If false, create a new XML element (unless tagId is
       not null).
geode-assembly/geode-assembly-test/src/main/java/org/apache/geode/session/tests/ContainerInstall.java