code: public static String canonicalize(String mathml) throws IOException, JDOMException, XMLStreamException, ModuleException {
          InputStream input = IOUtils.toInputStream(mathml, StandardCharsets.UTF_8.toString());
          final ByteArrayOutputStream output = new ByteArrayOutputStream();
          CANONICALIZER.canonicalize(input, output);
          String result = output.toString(StandardCharsets.UTF_8.toString());
  
          // since we can't properly configure the canonicalizer we need to adjust the result string
          // 1. omit xml header since it will not be used
  //        result = StringUtils.remove(result, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
          // 2. switch to the line separator used by the system
  
          result = result.replaceAll("\\r\\n|\\r|\\n", System.getProperty("line.separator"));
  
          return result;
      }
docs: Canonicalize an input MathML string.
  Line separators are system dependant.
  
  @param mathml MathML string
  @return Canonicalized MathML string
  @throws JDOMException      problem with DOM
  @throws IOException        problem with streams
  @throws ModuleException    some module cannot canonicalize the input
  @throws XMLStreamException an error with XML processing occurs