com.partnersoft.formats.xml
Class XmlBuilder

java.lang.Object
  extended by com.partnersoft.formats.xml.XmlBuilder
Direct Known Subclasses:
HtmlBuilder, KmlWriter

public class XmlBuilder
extends java.lang.Object

Builds an XML file via a variety of convenience methods.

XMLBuilder also aids accuracy by correctly escaping illegal symbols in content and attribute values, and by tracking and enforcing tag nesting.

Output is attractively indented at no additional cost.

Copyright 2003-2006 Partner Software, Inc.

Version:
$Id: XmlBuilder.java 2328 2010-01-06 15:38:22Z paul $
Author:
Paul Reavis

Constructor Summary
XmlBuilder(java.io.File outputFile)
           
XmlBuilder(VfsFile outputFile)
           
XmlBuilder(java.io.Writer writer)
           
XmlBuilder(java.io.Writer writer, boolean printDoctype)
           
 
Method Summary
 void beginStartTag(java.lang.String tagName)
           
 void close()
           
 void endElement()
           
 void endElement(boolean newLine)
           
 void endElement(java.lang.String checkTagName)
           
 void endElement(java.lang.String checkTagName, boolean newLine)
           
 void endStartTag()
           
 boolean isDroppingElementsWithoutContent()
           
 boolean isEmptyingElementsWithoutContent()
           
 void setDroppingElementsWithoutContent(boolean droppingElementsWithoutContent)
          If set to true, will not output elements specified by writeElement() if the content is null or blank.
 void setEmptyingElementsWithoutContent(boolean emptyingElementsWithoutContent)
          If set to true, uses the empty element form (e.g.
 void startElement(java.lang.String tagName)
           
 void startElement(java.lang.String tagName, boolean newLine)
           
 void startElement(java.lang.String tagName, java.lang.String... attributes)
           
 void writeAttribute(java.lang.String name, java.lang.String value)
           
 void writeContent(java.lang.Object content)
           
 void writeContent(java.lang.Object content, boolean newLine)
           
 void writeElement(java.lang.String tag, double content)
           
 void writeElement(java.lang.String tag, int content)
           
 void writeElement(java.lang.String tag, java.lang.Object content)
           
 void writeEmptyElement(java.lang.String tagName, java.lang.String... attributes)
           
 void writeIterableContent(java.lang.String tagName, java.lang.Iterable content)
           
 void writeRaw(java.lang.String text)
          This writes text directly to the file, without escaping XML characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlBuilder

public XmlBuilder(VfsFile outputFile)
           throws java.io.IOException
Throws:
java.io.IOException

XmlBuilder

public XmlBuilder(java.io.File outputFile)
           throws java.io.IOException
Throws:
java.io.IOException

XmlBuilder

public XmlBuilder(java.io.Writer writer)
           throws java.io.IOException
Throws:
java.io.IOException

XmlBuilder

public XmlBuilder(java.io.Writer writer,
                  boolean printDoctype)
           throws java.io.IOException
Throws:
java.io.IOException
Method Detail

startElement

public void startElement(java.lang.String tagName)
                  throws java.io.IOException
Throws:
java.io.IOException

startElement

public void startElement(java.lang.String tagName,
                         boolean newLine)
                  throws java.io.IOException
Throws:
java.io.IOException

startElement

public void startElement(java.lang.String tagName,
                         java.lang.String... attributes)
                  throws java.io.IOException
Throws:
java.io.IOException

endElement

public void endElement()
                throws java.io.IOException
Throws:
java.io.IOException

endElement

public void endElement(boolean newLine)
                throws java.io.IOException
Throws:
java.io.IOException

endElement

public void endElement(java.lang.String checkTagName)
                throws java.io.IOException
Throws:
java.io.IOException

endElement

public void endElement(java.lang.String checkTagName,
                       boolean newLine)
                throws java.io.IOException
Throws:
java.io.IOException

beginStartTag

public void beginStartTag(java.lang.String tagName)
                   throws java.io.IOException
Throws:
java.io.IOException

writeAttribute

public void writeAttribute(java.lang.String name,
                           java.lang.String value)
                    throws java.io.IOException
Throws:
java.io.IOException

endStartTag

public void endStartTag()
                 throws java.io.IOException
Throws:
java.io.IOException

writeEmptyElement

public void writeEmptyElement(java.lang.String tagName,
                              java.lang.String... attributes)
                       throws java.io.IOException
Throws:
java.io.IOException

writeElement

public void writeElement(java.lang.String tag,
                         java.lang.Object content)
                  throws java.io.IOException
Throws:
java.io.IOException

writeElement

public void writeElement(java.lang.String tag,
                         double content)
                  throws java.io.IOException
Throws:
java.io.IOException

writeElement

public void writeElement(java.lang.String tag,
                         int content)
                  throws java.io.IOException
Throws:
java.io.IOException

writeContent

public void writeContent(java.lang.Object content)
                  throws java.io.IOException
Throws:
java.io.IOException

writeContent

public void writeContent(java.lang.Object content,
                         boolean newLine)
                  throws java.io.IOException
Throws:
java.io.IOException

writeIterableContent

public void writeIterableContent(java.lang.String tagName,
                                 java.lang.Iterable content)
                          throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

writeRaw

public void writeRaw(java.lang.String text)
              throws java.io.IOException
This writes text directly to the file, without escaping XML characters. Use if you just want to dump already-formatted XML.

Throws:
java.io.IOException

isDroppingElementsWithoutContent

public boolean isDroppingElementsWithoutContent()

setDroppingElementsWithoutContent

public void setDroppingElementsWithoutContent(boolean droppingElementsWithoutContent)
If set to true, will not output elements specified by writeElement() if the content is null or blank.

Parameters:
droppingElementsWithoutContent -

isEmptyingElementsWithoutContent

public boolean isEmptyingElementsWithoutContent()

setEmptyingElementsWithoutContent

public void setEmptyingElementsWithoutContent(boolean emptyingElementsWithoutContent)
If set to true, uses the empty element form (e.g. for output elements specified by writeElement() if the content is null or blank.

Parameters:
emptyingElementsWithoutContent -