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 ; }
Canonicalize an input MathML string . Line separators are system dependant .