Class PrettyXMLWriter

  • All Implemented Interfaces:
    XMLWriter

    public class PrettyXMLWriter
    extends java.lang.Object
    implements XMLWriter
    Implementation of XMLWriter which emits nicely formatted documents to a PrintWriter.
    Since:
    1.3
    Author:
    Thomas Down
    • Constructor Summary

      Constructors 
      Constructor Description
      PrettyXMLWriter​(java.io.PrintWriter writer)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attribute​(java.lang.String qName, java.lang.String value)
      Add an un-qualified attribute to an element.
      void attribute​(java.lang.String nsURI, java.lang.String localName, java.lang.String value)
      Add an attribute to an element.
      void close()
      Close this XMLWriter, and its underlying stream.
      void closeTag​(java.lang.String qName)
      Closes an un-qualified element.
      void closeTag​(java.lang.String nsURI, java.lang.String localName)
      Closes an element
      void declareNamespace​(java.lang.String nsURI, java.lang.String prefixHint)
      Declare a namespace for current and following elements 'prefixHint' is ignored entirely in this implementation
      protected void numericalEntity​(char c)  
      void openTag​(java.lang.String qName)
      Open a new unqualified XML tag.
      void openTag​(java.lang.String nsURI, java.lang.String localName)
      Open a new namespace-qualified XML tag.
      void print​(java.lang.String data)
      Prints some textual content in an element.
      protected void printAttributeValue​(java.lang.String data)  
      protected void printChars​(java.lang.String data)  
      void println​(java.lang.String data)
      Prints some textual content, terminated with a newline character.
      void printRaw​(java.lang.String data)
      Send raw data to the stream.
      protected void writeIndent()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PrettyXMLWriter

        public PrettyXMLWriter​(java.io.PrintWriter writer)
    • Method Detail

      • declareNamespace

        public void declareNamespace​(java.lang.String nsURI,
                                     java.lang.String prefixHint)
                              throws java.io.IOException
        Declare a namespace for current and following elements 'prefixHint' is ignored entirely in this implementation
        Specified by:
        declareNamespace in interface XMLWriter
        Parameters:
        nsURI - The namespace to declare
        prefixHint - A suggested prefix-string for this namespace.
        Throws:
        java.io.IOException
      • writeIndent

        protected void writeIndent()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • openTag

        public void openTag​(java.lang.String nsURI,
                            java.lang.String localName)
                     throws java.io.IOException
        Description copied from interface: XMLWriter
        Open a new namespace-qualified XML tag.
        Specified by:
        openTag in interface XMLWriter
        Parameters:
        nsURI - A URI for the namespace to use
        localName - The name of the tag
        Throws:
        java.io.IOException
      • openTag

        public void openTag​(java.lang.String qName)
                     throws java.io.IOException
        Description copied from interface: XMLWriter
        Open a new unqualified XML tag. This may also be used if you want to do namespace management yourself, independantly of the XMLWriter
        Specified by:
        openTag in interface XMLWriter
        Parameters:
        qName - The name of the tag.
        Throws:
        java.io.IOException
      • attribute

        public void attribute​(java.lang.String nsURI,
                              java.lang.String localName,
                              java.lang.String value)
                       throws java.io.IOException
        Description copied from interface: XMLWriter
        Add an attribute to an element. This will throw an exception if it's not called immediately after an openTag command.
        Specified by:
        attribute in interface XMLWriter
        Parameters:
        nsURI - A URI for the namespace to use
        localName - The name of the attribute
        value - The textual value of the attribute
        Throws:
        java.io.IOException
      • attribute

        public void attribute​(java.lang.String qName,
                              java.lang.String value)
                       throws java.io.IOException
        Description copied from interface: XMLWriter
        Add an un-qualified attribute to an element. This will throw an exception if it's not called immediately after an openTag command.
        Specified by:
        attribute in interface XMLWriter
        Parameters:
        qName - The name of the attribute to set
        value - The textual value of the attribute
        Throws:
        java.io.IOException
      • closeTag

        public void closeTag​(java.lang.String nsURI,
                             java.lang.String localName)
                      throws java.io.IOException
        Description copied from interface: XMLWriter
        Closes an element
        Specified by:
        closeTag in interface XMLWriter
        Parameters:
        nsURI - A URI for the namespace to use
        localName - The name of the tag
        Throws:
        java.io.IOException
      • closeTag

        public void closeTag​(java.lang.String qName)
                      throws java.io.IOException
        Description copied from interface: XMLWriter
        Closes an un-qualified element.
        Specified by:
        closeTag in interface XMLWriter
        Parameters:
        qName - The tag name
        Throws:
        java.io.IOException
      • println

        public void println​(java.lang.String data)
                     throws java.io.IOException
        Description copied from interface: XMLWriter
        Prints some textual content, terminated with a newline character.
        Specified by:
        println in interface XMLWriter
        Throws:
        java.io.IOException
      • print

        public void print​(java.lang.String data)
                   throws java.io.IOException
        Description copied from interface: XMLWriter
        Prints some textual content in an element.
        Specified by:
        print in interface XMLWriter
        Throws:
        java.io.IOException
      • printRaw

        public void printRaw​(java.lang.String data)
                      throws java.io.IOException
        Description copied from interface: XMLWriter
        Send raw data to the stream. Mainly useful for things like DOCTYPE declarations. Use with care!
        Specified by:
        printRaw in interface XMLWriter
        Parameters:
        data - a string of data to include verbatim in the XML stream
        Throws:
        java.io.IOException
      • printChars

        protected void printChars​(java.lang.String data)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • printAttributeValue

        protected void printAttributeValue​(java.lang.String data)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • numericalEntity

        protected void numericalEntity​(char c)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: XMLWriter
        Close this XMLWriter, and its underlying stream.
        Specified by:
        close in interface XMLWriter
        Throws:
        java.io.IOException