@SuppressWarnings(value="Instanceof")
class StreamingMarkupBuilder
extends AbstractStreamingBuilder
A builder class for creating XML markup. This implementation uses a StreamingMarkupWriter to handle output.
Example:
System.out << new StreamingMarkupBuilder().bind {
root {
a( a1:'one' ) {
b { mkp.yield( '3 < 5' ) }
c( a2:'two', 'blah' )
}
}
}
Will output the following String, without newlines or indentation:
<root>
<a a1='one'>
<b>3 < 5</b>
<c a2='two'>blah</c>
</a>
</root>
Notes:
mkp is a special namespace used to escape
away from the normal building mode of the builder and get access
to helper markup methods 'yield', 'pi', 'comment', 'out',
'namespaces', 'xmlDeclaration' and 'yieldUnescaped'.
| Type | Name and description |
|---|---|
Object |
builderBacking namespace-aware builder reused for each bind(Closure) call. |
Object |
commentClosureInvoked by calling mkp.comment |
Object |
declarationClosureInvoked by calling mkp.xmlDeclaration |
Object |
encodingOptional encoding snapshot applied when bound markup is later written. |
boolean |
expandEmptyElementsWhether empty elements are rendered as explicit start/end pairs instead of empty-element tags. |
Object |
noopClosureInvoked by calling mkp.yield. |
Object |
pendingStackStack of namespace declarations suspended while nested elements are rendered. |
Object |
piClosureInvoked by calling mkp.pi |
Object |
tagClosureDefault element-emitting closure used for ordinary builder nodes. |
Object |
unescapedClosureInvoked by calling mkp.yieldUnescaped. |
boolean |
useDoubleQuotesWhether generated XML prefers double quotes when quoting attributes and declarations. |
| Properties inherited from class | Properties |
|---|---|
class AbstractStreamingBuilder |
aliasSetupClosure, badTagClosure, builder, getNamespaceClosure, namespaceSetupClosure, specialTags, toMapStringClosure |
| Constructor and description |
|---|
StreamingMarkupBuilder()Creates a streaming markup builder with the standard mkp helper tags installed. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
Object |
bind(Object closure)Returns a Writable object, which may be used to render the markup directly to a String, or send the output to a stream. |
|
Object |
bindNode(Object node)Convenience method for binding a single node. |
|
Object |
getQt()Returns the quote character currently preferred for generated XML. |
Backing namespace-aware builder reused for each bind(Closure) call.
Invoked by calling mkp.comment
Invoked by calling mkp.xmlDeclaration
Optional encoding snapshot applied when bound markup is later written.
Whether empty elements are rendered as explicit start/end pairs instead of empty-element tags.
Invoked by calling mkp.yield. Used to render text to the
output stream. Any XML reserved characters will be escaped to ensure
well-formedness.
Stack of namespace declarations suspended while nested elements are rendered.
Invoked by calling mkp.pi
Default element-emitting closure used for ordinary builder nodes.
Invoked by calling mkp.yieldUnescaped. Used to render
literal text or markup to the output stream. No escaping is done on the
output.
Whether generated XML prefers double quotes when quoting attributes and declarations.
Creates a streaming markup builder with the standard mkp helper tags installed.
Returns a Writable object, which may be used to render the markup directly to a String, or send the output to a stream.
Examples:
// get the markup as a string:
new StreamingMarkupBuilder().bind { div { out << 'hello world' } }.toString()
// send the output directly to a file:
new StreamingMarkupBuilder().bind {
div { out << 'hello world' }
}.writeTo( new File('myFile.xml').newWriter() )
closure - closure describing the XML to generate Convenience method for binding a single node.
The call bindNode(node) is equivalent to bind{ out << node }.
Returns a Writable object, which may be used to render
the markup directly to a String, or send the output to a stream.
node - node or value to write through the builderReturns the quote character currently preferred for generated XML.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.