Class PrettyXMLWriter

java.lang.Object
org.biojava.nbio.core.util.PrettyXMLWriter
All Implemented Interfaces:
XMLWriter

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

    • PrettyXMLWriter

      public PrettyXMLWriter(PrintWriter writer)
  • Method Details

    • declareNamespace

      public void declareNamespace(String nsURI, String prefixHint) throws IOException
      Description copied from interface: XMLWriter
      Hints that a namespace is going to be used in a sub-tree. Use this method to avoid namespaces that are used only in leaf-nodes of a tree being re-defined every time they are used. The XMLWriter will generally try to use the suggested prefix for this namespace, but there is no guarentee of this. In particular, if the namespace is already in use, the current prefix will still be used. Similarly if the suggested prefix has already been used for another namespace, a new one will be auto-generated.
      Specified by:
      declareNamespace in interface XMLWriter
      Parameters:
      nsURI - The namespace to declare
      prefixHint - A suggested prefix-string for this namespace.
      Throws:
      IOException
    • writeIndent

      protected void writeIndent() throws IOException
      Throws:
      IOException
    • openTag

      public void openTag(String nsURI, String localName) throws 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:
      IOException
    • openTag

      public void openTag(String qName) throws 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:
      IOException
    • attribute

      public void attribute(String nsURI, String localName, String value) throws 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:
      IOException
    • attribute

      public void attribute(String qName, String value) throws 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:
      IOException
    • closeTag

      public void closeTag(String nsURI, String localName) throws 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:
      IOException
    • closeTag

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

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

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

      public void printRaw(String data) throws 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:
      IOException
    • printChars

      protected void printChars(String data) throws IOException
      Throws:
      IOException
    • printAttributeValue

      protected void printAttributeValue(String data) throws IOException
      Throws:
      IOException
    • numericalEntity

      protected void numericalEntity(char c) throws IOException
      Throws:
      IOException
    • close

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