Class MjmlParser

java.lang.Object
dev.jcputney.mjml.parser.MjmlParser

public final class MjmlParser extends Object
Parses preprocessed MJML source into an MjmlDocument. Uses the JDK DOM parser to build a DOM tree, then converts it to our lightweight MjmlNode tree.
  • Method Details

    • cleanUp

      public static void cleanUp()
      Removes the thread-local DocumentBuilder for the current thread. Call this in application-server environments where threads are recycled (e.g., in a servlet filter's destroy() or a thread-pool shutdown hook) to avoid retaining ~50-100KB of XML parser infrastructure per thread.

      Not required in short-lived applications or environments with fixed thread pools, where keeping the DocumentBuilder warm avoids repeated construction overhead.

    • parse

      public static MjmlDocument parse(String mjmlSource)
      Parses raw MJML source into an MjmlDocument using the default maximum nesting depth. The source is preprocessed (CDATA wrapping, entity replacement) before XML parsing.
      Parameters:
      mjmlSource - the raw MJML markup to parse
      Returns:
      the parsed MjmlDocument
    • parse

      public static MjmlDocument parse(String mjmlSource, int maxNestingDepth)
      Parses raw MJML source into an MjmlDocument with a configurable maximum nesting depth. The source is preprocessed (CDATA wrapping, entity replacement) before XML parsing.
      Parameters:
      mjmlSource - the raw MJML markup
      maxNestingDepth - maximum allowed element nesting depth
      Returns:
      the parsed MjmlDocument