Package com.pnfsoftware.jeb.util.format
Class XmlBuilder
java.lang.Object
com.pnfsoftware.jeb.util.format.TextBuilder
com.pnfsoftware.jeb.util.format.XmlBuilder
- All Implemented Interfaces:
Appendable
A specialized text builder used to craft XML documents sequentially.
-
Constructor Summary
ConstructorsConstructorDescriptionXmlBuilder
(int indentationSize) XmlBuilder
(int indentationSize, int initialCapacity) -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendHeader
(int versionMajor, int versionMinor, String encoding, boolean standalone) Append an XML header.void
Append a standard 1.0 header specifying a UTF-8 encoding and standalone=no.void
Close the last opened element.void
closeElement
(boolean appendLine) Close the last opened element.static CharSequence
static CharSequence
Escape an XML attribute data string.static CharSequence
Escape an XML text data string.void
openElement
(String name) Output an XML element with attributes.void
openElement
(String name, Map<String, String> attributes) Output an XML element with attributes.void
openElement
(String name, Map<String, String> attributes, boolean close) Output an XML element with attributes.Methods inherited from class com.pnfsoftware.jeb.util.format.TextBuilder
append, append, append, append, append, append, append, append, append, append, append, appendLine, appendLine, appendLine, clear, eol, indent, indent, length, removeChar, removeChars, removeLastChar, removeLastLine, space, toString, unindent, updateIndentation
-
Constructor Details
-
XmlBuilder
public XmlBuilder() -
XmlBuilder
public XmlBuilder(int indentationSize) -
XmlBuilder
public XmlBuilder(int indentationSize, int initialCapacity)
-
-
Method Details
-
appendStandardHeader
public void appendStandardHeader()Append a standard 1.0 header specifying a UTF-8 encoding and standalone=no. -
appendHeader
Append an XML header.- Parameters:
versionMajor
-versionMinor
-encoding
-standalone
-
-
openElement
Output an XML element with attributes. The element is not not output- Parameters:
name
-
-
openElement
Output an XML element with attributes. The closing tag is not output.- Parameters:
name
-attributes
- optional attributes
-
openElement
Output an XML element with attributes.- Parameters:
name
- the element nameattributes
- optional map of attributes name->value, which must be escaped (this method will append the attributes' names and values as-is)close
- if true, the tag is immediately closed using "/>"
-
closeElement
public void closeElement()Close the last opened element. -
closeElement
public void closeElement(boolean appendLine) Close the last opened element.- Parameters:
appendLine
- if true, a new line is appended after the closing tag
-
escapeTextData
Escape an XML text data string.- Parameters:
s
-- Returns:
-
escapeAttributeData
Escape an XML attribute data string.- Parameters:
s
-- Returns:
-
escapeAll
-