Package groovy.xml
Class SerializeOptions
java.lang.Object
groovy.xml.SerializeOptions
Options for controlling XML serialization via
XmlUtil.serialize(org.w3c.dom.Element).
All options have sensible defaults matching the existing behaviour of
XmlUtil.serialize(), so only options that need to differ from
the defaults need to be specified:
// Groovy named parameters: XmlUtil.serialize(node, new SerializeOptions(encoding: 'ISO-8859-1', indent: 4))
- Since:
- 6.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new options instance using the default serialization settings. -
Method Summary
Modifier and TypeMethodDescriptionThe character encoding as aCharset.The character encoding for the XML output.intThe number of spaces to use for indentation.booleanWhether to allow DOCTYPE declarations during serialization.booleanWhether the underlyingTransformerFactorymay resolve external DTDs and stylesheets (e.g.voidsetAllowDocTypeDeclaration(boolean allowDocTypeDeclaration) Sets whether DOCTYPE declarations are allowed during serialization.voidsetAllowExternalResources(boolean allowExternalResources) Sets whether external DTDs and stylesheets may be resolved during serialization.voidsetEncoding(String encoding) Sets the character encoding for the XML output.voidsetIndent(int indent) Sets the number of spaces to use for indentation.
-
Constructor Details
-
SerializeOptions
public SerializeOptions()Creates a new options instance using the default serialization settings.
-
-
Method Details
-
getEncoding
The character encoding for the XML output. Default is"UTF-8".- Returns:
- the encoding name
-
setEncoding
Sets the character encoding for the XML output.- Parameters:
encoding- the encoding name to use
-
getCharset
The character encoding as aCharset.- Returns:
- the Charset for the configured encoding
-
getIndent
public int getIndent()The number of spaces to use for indentation. Default is2.- Returns:
- the indent amount
-
setIndent
public void setIndent(int indent) Sets the number of spaces to use for indentation.- Parameters:
indent- the indent amount
-
isAllowDocTypeDeclaration
public boolean isAllowDocTypeDeclaration()Whether to allow DOCTYPE declarations during serialization. Default isfalse.- Returns:
- true if DOCTYPE declarations are allowed
-
setAllowDocTypeDeclaration
public void setAllowDocTypeDeclaration(boolean allowDocTypeDeclaration) Sets whether DOCTYPE declarations are allowed during serialization.- Parameters:
allowDocTypeDeclaration-trueto allow DOCTYPE declarations
-
isAllowExternalResources
public boolean isAllowExternalResources()Whether the underlyingTransformerFactorymay resolve external DTDs and stylesheets (e.g. via<xsl:import>or<xsl:include>). Default isfalse; set totruewhen serializing XSLT documents that legitimately reference external resources.- Returns:
trueif external resource resolution is allowed- Since:
- 6.0.0
-
setAllowExternalResources
public void setAllowExternalResources(boolean allowExternalResources) Sets whether external DTDs and stylesheets may be resolved during serialization.- Parameters:
allowExternalResources-trueto allow external resource resolution- Since:
- 6.0.0
-