Class XSDOMSerializer

java.lang.Object
com.io7m.xstructural.vanilla.internal.format.XSDOMSerializer

public final class XSDOMSerializer extends Object
Serializes an Document to an XML 1.0 string.

The serializer is a partial function defined on well-formed XML 1.0 documents. It rejects any element content or attribute value that contains a character outside the XML 1.0 Char production. It never emits markup that is not well-formed, and it never allows text or attribute content to break out of the element in which it occurs.

The layout policy is a single line width: start tags whose attribute list would exceed the width are wrapped, one attribute per line. The serialized string carries exactly one trailing newline.

  • Method Details

    • of

      public static XSDOMSerializer of(int maxWidth)
      Create a serializer.
      Parameters:
      maxWidth - The maximum line width
      Returns:
      A serializer
      Throws:
      IllegalArgumentException - If the width is not positive
    • serialize

      public String serialize(Document inDoc, XSProlog inProlog)
      Serialize a document.
      Parameters:
      inDoc - The document
      inProlog - The prolog to emit before the root element
      Returns:
      The serialized string
      Throws:
      IllegalArgumentException - If the document has no root element, or if any content contains an illegal XML 1.0 character