Class XMLWriter


  • public class XMLWriter
    extends java.lang.Object
    XML document writer based upon a XMLTagWriter tree.

    Use like this:

            XMLWriter wr = new XMLWriter(
                    new FileWriter( "test.xml" ),
                    new MyRootTagWriter()
            );
            // optionally define the DTD
            wr.setDtd(
                    new String[]{
                            "faces-config" // name
                            "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN", // public
                            "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"  // system
            }
            );
            // optionally set encoding
            wr.setEncoding("UTF-8");
    
            // write
            try
        {
                    wr.write( new MyRootDataObject() );
        }
            catch( XMLWriteException e )
        {
                    // report some error
        }
            finally
        {
                    try{ wr.close() } catch( IOException e ){}
        }
     
    • Constructor Detail

      • XMLWriter

        public XMLWriter​(java.io.Writer wr,
                         XMLTagWriter root)
        Creates a new xml writer which wraps a exiting Writer.
        Parameters:
        wr - the underlying writer
        root - the root tag writer, must contain all sub tag writers of the document
      • XMLWriter

        public XMLWriter​(java.io.OutputStream os,
                         XMLTagWriter root)
        Creates a new xml writer which wraps a exiting OutputStream.
        Parameters:
        os - the underlying output stream
        root - the root tag writer, must contain all sub tag writers of the document
    • Method Detail

      • createXMLOutputter

        protected org.znerd.xmlenc.XMLOutputter createXMLOutputter​(java.io.Writer wr)
                                                            throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • endDocument

        protected void endDocument​(org.znerd.xmlenc.XMLOutputter xout)
      • close

        public void close()
                   throws java.lang.IllegalStateException,
                          java.io.IOException
        Throws:
        java.lang.IllegalStateException
        java.io.IOException
      • getDtd

        public java.lang.String[] getDtd()
      • setDtd

        public void setDtd​(java.lang.String[] dtd)
      • getEncoding

        public java.lang.String getEncoding()
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
      • getIndent

        public java.lang.String getIndent()
      • setIndent

        public void setIndent​(java.lang.String indent)
      • getLineBreak

        public org.znerd.xmlenc.LineBreak getLineBreak()
      • setLineBreak

        public void setLineBreak​(org.znerd.xmlenc.LineBreak lineBreak)
      • getQuotation

        public char getQuotation()
      • setQuotation

        public void setQuotation​(char quotation)