code: public static String trimElements(String xml) {
          String result = xml.trim();
          Matcher matcher = ELEMENT_CONTENT_PATTERN.matcher(result);
          return matcher.replaceAll(">$1<");
      }
docs: Removes whitespace before and after each elements (and the entire document).
  @param xml XML to trim.
  @return trimmed version.