Package gnu.xml

Class XMLPrinter

All Implemented Interfaces:
Consumer, PositionConsumer, XConsumer, Closeable, Flushable, Appendable, AutoCloseable, Consumer<Object>, DoubleConsumer, IntConsumer, LongConsumer

public class XMLPrinter extends PrintConsumer implements PositionConsumer, XConsumer
Print an event stream in XML format on a PrintWriter.
  • Field Details

    • printIndent

      protected int printIndent
    • indentAttributes

      public boolean indentAttributes
      When indenting, should attributes be lined up?
    • canonicalizeCDATA

      public boolean canonicalizeCDATA
    • useEmptyElementTag

      public int useEmptyElementTag
      Handling of empty elements. 0: No element element tags, as required for canonical XML: <br></br>. 1: Use XML-style empty element tags: <br/> 2: Use HTML-compatible empty element tags: <br /> but <p></p>.
    • escapeText

      public boolean escapeText
    • escapeNonAscii

      public boolean escapeNonAscii
    • extended

      public boolean extended
    • doctypeSystem

      public static final ThreadLocation doctypeSystem
      Fluid parameter to control whether a DOCTYPE declaration is emitted. If non-null, this is the the public identifier.
    • doctypePublic

      public static final ThreadLocation doctypePublic
      The system identifier emitted in a DOCTYPE declaration. Has no effect if doctypeSystem returns null. If non-null, this is the the system identifier.
    • indentLoc

      public static final ThreadLocation<String> indentLoc
  • Constructor Details

    • XMLPrinter

      public XMLPrinter(Writer out, boolean autoFlush)
    • XMLPrinter

      public XMLPrinter(Writer out)
    • XMLPrinter

      public XMLPrinter(Consumer out)
    • XMLPrinter

      public XMLPrinter(PrintConsumer out)
    • XMLPrinter

      public XMLPrinter(OutputStream out)
  • Method Details

    • setPrintXMLdecl

      public void setPrintXMLdecl(boolean value)
    • make

      public static XMLPrinter make(Consumer out, Object style)
    • toString

      public static String toString(Object value)
      Convert argument to string in XML syntax.
    • setStyle

      public void setStyle(Object style)
    • setEscapeText

      public void setEscapeText(boolean v)
    • setEscapeNonAscii

      public void setEscapeNonAscii(boolean v)
    • setCanonicalizeCDATA

      public void setCanonicalizeCDATA(boolean v)
    • setUseEmptyElementTag

      public void setUseEmptyElementTag(int v)
    • setExtended

      public void setExtended(boolean v)
    • setIndent

      public void setIndent(int v)
      Controls whether to add extra indentation. -1: don't add indentation; 0: pretty-print (avoid needless newlines); 1: indent (force).
    • write

      public void write(int v)
      Specified by:
      write in interface Consumer
      Overrides:
      write in class PrintWriter
    • writeBoolean

      public void writeBoolean(boolean v)
      Specified by:
      writeBoolean in interface Consumer
      Overrides:
      writeBoolean in class PrintConsumer
    • startNumber

      protected void startNumber()
      Overrides:
      startNumber in class PrintConsumer
    • endNumber

      protected void endNumber()
      Overrides:
      endNumber in class PrintConsumer
    • closeTag

      public void closeTag()
    • startDocument

      public void startDocument()
      Specified by:
      startDocument in interface Consumer
      Overrides:
      startDocument in class PrintConsumer
    • endDocument

      public void endDocument()
      Specified by:
      endDocument in interface Consumer
      Overrides:
      endDocument in class PrintConsumer
    • beginEntity

      public void beginEntity(Object base)
      Specified by:
      beginEntity in interface XConsumer
      Overrides:
      beginEntity in class PrintConsumer
    • endEntity

      public void endEntity()
      Specified by:
      endEntity in interface XConsumer
      Overrides:
      endEntity in class PrintConsumer
    • writeQName

      protected void writeQName(Object name)
    • writeDoctypeIfDefined

      public void writeDoctypeIfDefined(String tagname)
      Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublic
    • writeDoctype

      public void writeDoctype(String tagname, String systemId, String publicId)
    • startElement

      public void startElement(Object type)
      Specified by:
      startElement in interface Consumer
      Overrides:
      startElement in class PrintConsumer
    • isHtmlEmptyElementTag

      public static boolean isHtmlEmptyElementTag(String name)
    • getHtmlTag

      protected String getHtmlTag(Object type)
    • endElement

      public void endElement()
      Specified by:
      endElement in interface Consumer
      Overrides:
      endElement in class PrintConsumer
    • startAttribute

      public void startAttribute(Object attrType)
      Write a attribute for the current element. This is only allowed immediately after a startElement.
      Specified by:
      startAttribute in interface Consumer
      Overrides:
      startAttribute in class PrintConsumer
    • endAttribute

      public void endAttribute()
      Description copied from interface: Consumer
      End of an attribute or end of an actual parameter. The former use matches a startAttribute; the latter may not, and can be used to separate parameters in a parameter list. This double duty suggsts the method should at least be re-named.
      Specified by:
      endAttribute in interface Consumer
      Overrides:
      endAttribute in class PrintConsumer
    • writeDouble

      public void writeDouble(double d)
      Specified by:
      writeDouble in interface Consumer
      Overrides:
      writeDouble in class PrintConsumer
    • writeFloat

      public void writeFloat(float f)
      Specified by:
      writeFloat in interface Consumer
      Overrides:
      writeFloat in class PrintConsumer
    • formatDouble

      public static String formatDouble(double d)
      Helper to format xs:double according to XPath/XQuery specification.
    • formatFloat

      public static String formatFloat(float f)
      Helper to format xs:float according to XPath/XQuery specification.
    • formatDecimal

      public static String formatDecimal(BigDecimal dec)
      Format java.math.BigDecimal as needed for XPath/XQuery's xs:decimal. Specifically this means removing trailing fractional zeros, and a trailing decimal point. However, note that the XML Schema canonical representation does require a decimal point and at least one fractional digit.
    • print

      public void print(Object v)
      Overrides:
      print in class PrintWriter
    • writeObject

      public void writeObject(Object v)
      Specified by:
      writeObject in interface Consumer
      Overrides:
      writeObject in class PrintConsumer
    • ignoring

      public boolean ignoring()
      True if consumer is ignoring rest of element. The producer can use this information to skip ahead.
      Specified by:
      ignoring in interface Consumer
      Overrides:
      ignoring in class PrintConsumer
    • write

      public void write(String str, int start, int length)
      Overrides:
      write in class PrintWriter
    • write

      public void write(char[] buf, int off, int len)
      Specified by:
      write in interface Consumer
      Overrides:
      write in class PrintWriter
    • writePosition

      public void writePosition(AbstractSequence seq, int ipos)
      Description copied from interface: PositionConsumer
      Consume a single position pair. This PositionConsumer may assume the sequence does no reference management; i.e. that copyPos is trivial and releasePos is a no-op. If that is not the case, use consume(TreePosition) instead.
      Specified by:
      writePosition in interface PositionConsumer
    • writeBaseUri

      public void writeBaseUri(Object uri)
    • beginComment

      public void beginComment()
    • endComment

      public void endComment()
    • writeComment

      public void writeComment(String chars)
    • writeComment

      public void writeComment(char[] chars, int offset, int length)
      Specified by:
      writeComment in interface XConsumer
      Overrides:
      writeComment in class PrintConsumer
    • writeCDATA

      public void writeCDATA(char[] chars, int offset, int length)
      Specified by:
      writeCDATA in interface XConsumer
      Overrides:
      writeCDATA in class PrintConsumer
    • writeProcessingInstruction

      public void writeProcessingInstruction(String target, char[] content, int offset, int length)
      Specified by:
      writeProcessingInstruction in interface XConsumer
      Overrides:
      writeProcessingInstruction in class PrintConsumer
    • writePosition

      public void writePosition(SeqPosition position)
      Description copied from interface: PositionConsumer
      Consume node at current position. The caller may invalidate or change the position after consume returns, so if the consumer wants to save it, it needs to copy it.
      Specified by:
      writePosition in interface PositionConsumer
    • error

      public void error(String msg, String code)