Class XmlWriter


  • class XmlWriter
    extends java.lang.Object
    Utility class for writing XML.
    Since:
    26 Aug 2008
    Author:
    Mark Taylor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String ENCODING  
      private int iLevel_  
      private int indent_  
      private java.io.Writer out_  
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlWriter​(java.io.OutputStream out, int indent)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the stream.
      void end​(java.lang.String element)
      End an element.
      void inline​(java.lang.String element, java.lang.String content)
      Write an element and its text content.
      void literal​(java.lang.String txt)
      Writes text with no escaping of XML special characters etc.
      void newline()
      Writes a new line character.
      private void pad​(int level)
      Outputs start-of-line padding for a given level of indentation.
      void sampValue​(java.lang.Object value)
      Writes a SAMP-friendly object in XML-RPC form.
      void start​(java.lang.String element)
      Start an element.
      void text​(java.lang.String txt)
      Writes text.
      • Methods inherited from class java.lang.Object

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

      • out_

        private final java.io.Writer out_
      • indent_

        private final int indent_
      • iLevel_

        private int iLevel_
    • Constructor Detail

      • XmlWriter

        public XmlWriter​(java.io.OutputStream out,
                         int indent)
                  throws java.io.IOException
        Constructor.
        Parameters:
        out - destination stream
        indent - number of spaces to indent each element level
        Throws:
        java.io.IOException
    • Method Detail

      • start

        public void start​(java.lang.String element)
                   throws java.io.IOException
        Start an element.
        Parameters:
        element - tag name
        Throws:
        java.io.IOException
      • end

        public void end​(java.lang.String element)
                 throws java.io.IOException
        End an element.
        Parameters:
        element - tag name
        Throws:
        java.io.IOException
      • inline

        public void inline​(java.lang.String element,
                           java.lang.String content)
                    throws java.io.IOException
        Write an element and its text content.
        Parameters:
        element - tag name
        content - element text content
        Throws:
        java.io.IOException
      • text

        public void text​(java.lang.String txt)
                  throws java.io.IOException
        Writes text. Any escaping required for XML output will be taken care of.
        Parameters:
        txt - text to output
        Throws:
        java.io.IOException
      • literal

        public void literal​(java.lang.String txt)
                     throws java.io.IOException
        Writes text with no escaping of XML special characters etc.
        Parameters:
        txt - raw text to output
        Throws:
        java.io.IOException
      • newline

        public void newline()
                     throws java.io.IOException
        Writes a new line character.
        Throws:
        java.io.IOException
      • sampValue

        public void sampValue​(java.lang.Object value)
                       throws java.io.IOException
        Writes a SAMP-friendly object in XML-RPC form.
        Parameters:
        value - object to serialize; must be a string, list or map
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Closes the stream.
        Throws:
        java.io.IOException
      • pad

        private void pad​(int level)
                  throws java.io.IOException
        Outputs start-of-line padding for a given level of indentation.
        Parameters:
        level - level of XML element ancestry
        Throws:
        java.io.IOException