Save This Page
Home » groovy-src-1.6.5 » groovy » xml » [javadoc | source]
groovy.xml
public class: MarkupBuilder [javadoc | source]
java.lang.Object
   groovy.lang.GroovyObjectSupport
      groovy.util.BuilderSupport
         groovy.xml.MarkupBuilder

All Implemented Interfaces:
    GroovyObject

A helper class for creating XML or HTML markup. This implementation outputs markup in a 'pretty printed' format.

Example:

new MarkupBuilder().root {
  a( a1:'one' ) {
    b { mkp.yield( '3 < 5' ) }
    c( a2:'two', 'blah' )
  }
}
Will print the following to System.out:
<root>
  <a a1='one'>
    <b>3 &lt; 5</b>
    <c a2='two'>blah</c>
  </a>
</root>
Note that mkp is a special namespace used to escape away from the normal building mode of the builder and get access to helper markup methods such as 'yield' and 'yieldUnescaped'. See the javadoc for #getMkp() for further details.
Constructor:
 public MarkupBuilder() 
 public MarkupBuilder(PrintWriter pw) 
    Sends markup to the given PrintWriter
    Parameters:
    pw - the PrintWriter to use
    Also see:
    IndentPrinter#IndentPrinter(PrintWriter)
 public MarkupBuilder(Writer writer) 
    Sends markup to the given Writer but first wrapping it in a PrintWriter
    Parameters:
    writer - the writer to use
    Also see:
    IndentPrinter#IndentPrinter(PrintWriter)
 public MarkupBuilder(IndentPrinter out) 
    Sends markup to the given IndentPrinter. Use this option if you want to customize the indent used.
    Parameters:
    out - the IndentPrinter to use
Method from groovy.xml.MarkupBuilder Summary:
createNode,   createNode,   createNode,   createNode,   getDoubleQuotes,   getMkp,   getName,   getPrinter,   isOmitEmptyAttributes,   isOmitNullAttributes,   nodeCompleted,   print,   setDoubleQuotes,   setOmitEmptyAttributes,   setOmitNullAttributes,   setParent,   transformValue,   yield,   yieldUnescaped
Methods from groovy.util.BuilderSupport:
createNode,   createNode,   createNode,   createNode,   doInvokeMethod,   getCurrent,   getName,   invokeMethod,   invokeMethod,   nodeCompleted,   postNodeCompletion,   setClosureDelegate,   setCurrent,   setParent
Methods from groovy.lang.GroovyObjectSupport:
getMetaClass,   getProperty,   invokeMethod,   setMetaClass,   setProperty
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from groovy.xml.MarkupBuilder Detail:
 protected Object createNode(Object name) 
 protected Object createNode(Object name,
    Object value) 
 protected Object createNode(Object name,
    Map attributes) 
 protected Object createNode(Object name,
    Map attributes,
    Object value) 
 public boolean getDoubleQuotes() 
    Returns true if attribute values are output with double quotes; false if single quotes are used. By default, single quotes are used.
 public Object getMkp() 
 protected Object getName(String methodName) 
 protected IndentPrinter getPrinter() 
 public boolean isOmitEmptyAttributes() 
    Determine whether empty attributes will appear in the produced markup.
 public boolean isOmitNullAttributes() 
    Determine whether null attributes will appear in the produced markup.
 protected  void nodeCompleted(Object parent,
    Object node) 
 protected  void print(Object node) 
 public  void setDoubleQuotes(boolean useDoubleQuotes) 
    Sets whether the builder outputs attribute values in double quotes or single quotes.
 public  void setOmitEmptyAttributes(boolean omitEmptyAttributes) 
    Allows empty attributes to be removed the produced markup.
 public  void setOmitNullAttributes(boolean omitNullAttributes) 
    Allows null attributes to be removed from the generated markup.
 protected  void setParent(Object parent,
    Object child) 
 protected String transformValue(String value) 
Deprecated!
    Returns a String with special XML characters escaped as entities so that output XML is valid. Escapes the following characters as corresponding entities:
    • \' as &apos;
    • & as &amp;
    • < as &lt;
    • > as &gt;
 public  void yield(String value) 
    Prints data in the body of the current tag, escaping XML entities. For example: mkp.yield('5 < 7')
 public  void yieldUnescaped(String value) 
    Print data in the body of the current tag. Does not escape XML entities. For example: mkp.yieldUnescaped('I am <i>happy</i>!').