code: private static String collapseNode(String xml, String name) {
          String answer = xml;
  
          Pattern pattern = Pattern.compile("<" + name + "(.*)></" + name + ">");
          Matcher matcher = pattern.matcher(answer);
          if (matcher.find()) {
              answer = matcher.replaceAll("<" + name + "$1/>");
          }
          return answer;
      }
docs: Collapses all the named node in the XML
  
  @param xml  the XML
  @param name the name of the node
  @return the XML with collapsed nodes