Interface XMLWriter

  • All Known Implementing Classes:
    PrettyXMLWriter

    public interface XMLWriter
    Simple interface for building XML documents.
    Since:
    1.3
    Author:
    Thomas Down
    • Method Summary

      All Methods Instance Methods Abstract 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 it's underlying stream.
      void closeTag​(java.lang.String name)
      Closes an un-qualified element.
      void closeTag​(java.lang.String nsURI, java.lang.String qName)
      Closes an element
      void declareNamespace​(java.lang.String nsURI, java.lang.String prefixHint)
      Hints that a namespace is going to be used in a sub-tree.
      void openTag​(java.lang.String name)
      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.
      void println​(java.lang.String data)
      Prints some textual content, terminated with a newline character.
      void printRaw​(java.lang.String s)
      Send raw data to the stream.
    • Method Detail

      • printRaw

        void printRaw​(java.lang.String s)
               throws java.io.IOException
        Send raw data to the stream. Mainly useful for things like DOCTYPE declarations. Use with care!
        Parameters:
        s - a string of data to include verbatim in the XML stream
        Throws:
        java.io.IOException
      • openTag

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

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

        void attribute​(java.lang.String nsURI,
                       java.lang.String localName,
                       java.lang.String value)
                throws java.io.IOException
        Add an attribute to an element. This will throw an exception if it's not called immediately after an openTag command.
        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

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

        void print​(java.lang.String data)
            throws java.io.IOException
        Prints some textual content in an element.
        Throws:
        java.io.IOException
      • println

        void println​(java.lang.String data)
              throws java.io.IOException
        Prints some textual content, terminated with a newline character.
        Throws:
        java.io.IOException
      • closeTag

        void closeTag​(java.lang.String nsURI,
                      java.lang.String qName)
               throws java.io.IOException
        Closes an element
        Parameters:
        nsURI - A URI for the namespace to use
        qName - The name of the tag
        Throws:
        java.io.IOException
      • closeTag

        void closeTag​(java.lang.String name)
               throws java.io.IOException
        Closes an un-qualified element.
        Parameters:
        name - The tag name
        Throws:
        java.io.IOException
      • declareNamespace

        void declareNamespace​(java.lang.String nsURI,
                              java.lang.String prefixHint)
                       throws java.io.IOException
        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.
        Parameters:
        nsURI - The namespace to declare
        prefixHint - A suggested prefix-string for this namespace.
        Throws:
        java.io.IOException
      • close

        void close()
            throws java.io.IOException
        Close this XMLWriter, and it's underlying stream.
        Throws:
        java.io.IOException
        Since:
        1.4