code: public static void format(final Source input, final Result output) {
          try {
              // Use an identity transformation to write the source to the result.
              final Transformer transformer = createTransformer(null);
              transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  
              transformer.transform(input, output);
          } catch (final Exception ex) {
              LOGGER.error("Problem formatting DOM representation.", ex);
          }
      }
docs: Format an XML {@link Source} to a pretty-printable {@link StreamResult}.
  
  @param input
  The (unformatted) input XML {@link Source}.
  @return The formatted {@link StreamResult}.