Package org.beanio.stream.xml
Class XmlParserConfiguration
- java.lang.Object
-
- org.beanio.stream.xml.XmlParserConfiguration
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
XmlRecordParserFactory
public class XmlParserConfiguration extends java.lang.Object implements java.lang.Cloneable
Stores configuration settings for parsing XML formatted streams.By default, indentation is disabled and an XML header will be written to an output stream.
- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description XmlParserConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNamespace(java.lang.String prefix, java.lang.String uri)
Adds a namespace to be set on the root element.protected XmlParserConfiguration
clone()
java.lang.String
getEncoding()
Returns the XML character encoding to include in the document header.int
getIndentation()
Returns the number of spaces to indent each level of XML, or-1
if indentation is disabled.java.lang.String
getLineSeparator()
Returns the text used to terminate a line when indentation is enabled.java.util.Map<java.lang.String,java.lang.String>
getNamespaceMap()
Returns a map of namespace URI's to prefixes to be set on the root element.java.lang.String
getVersion()
Returns the XML version to include in the document header.boolean
isIndentationEnabled()
Returns whether XML output will be indented.boolean
isSuppressHeader()
Returns whether the XML header is suppressed.void
setEncoding(java.lang.String encoding)
Sets the XML character encoding to include in the document header.void
setIndentation(int indentation)
Enables and sets the indentation level in spaces.void
setLineSeparator(java.lang.String lineSeparator)
Sets the text used to terminate a line when indentation is enabled.void
setNamespaces(java.lang.String list)
Sets the list of namespaces to be set on the root element.void
setSuppressHeader(boolean suppressHeader)
Sets whether the XML header is suppressed.void
setVersion(java.lang.String version)
Sets the XML version to include in the document header.
-
-
-
Method Detail
-
getIndentation
public int getIndentation()
Returns the number of spaces to indent each level of XML, or-1
if indentation is disabled.- Returns:
- the number of spaces to indent each level of XML,
or
-1
to disable indentation
-
setIndentation
public void setIndentation(int indentation)
Enables and sets the indentation level in spaces. If set to-1
(the default value), indentation is disabled.- Parameters:
indentation
- the number of spaces to indent each level of XML, or-1
to disable indentation
-
isIndentationEnabled
public boolean isIndentationEnabled()
Returns whether XML output will be indented.- Returns:
true
if indentation is enabled
-
getLineSeparator
public java.lang.String getLineSeparator()
Returns the text used to terminate a line when indentation is enabled. When set tonull
(the default), the line separator is set to the value of theline.separator
system property.- Returns:
- the line separation text
-
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparator)
Sets the text used to terminate a line when indentation is enabled. When set tonull
(the default), the line separator is set to the value of theline.separator
system property.- Parameters:
lineSeparator
- the line separation text
-
isSuppressHeader
public boolean isSuppressHeader()
Returns whether the XML header is suppressed. Defaults tofalse
.- Returns:
true
if the XML header is suppressed
-
setSuppressHeader
public void setSuppressHeader(boolean suppressHeader)
Sets whether the XML header is suppressed.- Parameters:
suppressHeader
-true
to suppress the XML header
-
getVersion
public java.lang.String getVersion()
Returns the XML version to include in the document header.- Returns:
- the XML version
-
setVersion
public void setVersion(java.lang.String version)
Sets the XML version to include in the document header. Defaults to1.0
. May not be set tonull
.- Parameters:
version
- the XML version
-
getEncoding
public java.lang.String getEncoding()
Returns the XML character encoding to include in the document header.- Returns:
- the XML character encoding
-
setEncoding
public void setEncoding(java.lang.String encoding)
Sets the XML character encoding to include in the document header. Defaults to 'utf-8
'. If set tonull
or empty string the document header will not include the encoding setting.- Parameters:
encoding
- the XML character encoding
-
addNamespace
public void addNamespace(java.lang.String prefix, java.lang.String uri)
Adds a namespace to be set on the root element.- Parameters:
prefix
- the namespace prefixuri
- the namespace URI
-
setNamespaces
public void setNamespaces(java.lang.String list)
Sets the list of namespaces to be set on the root element. The list should be formatted as a space delimited list of alternating prefixes and uri's. For example,setNamespaces("xsd http://www.w3.org/2001/XMLSchema b http://www.beanio.org/2011/01");
- Parameters:
list
- the space delimited list of namespaces
-
getNamespaceMap
public java.util.Map<java.lang.String,java.lang.String> getNamespaceMap()
Returns a map of namespace URI's to prefixes to be set on the root element.- Returns:
- the map of namespace prefixes to URI's
-
clone
protected XmlParserConfiguration clone()
- Overrides:
clone
in classjava.lang.Object
-
-