Package org.jibx.v2
Interface XmlWriter
public interface XmlWriter
XML writer interface used for output of marshalled document. This interface allows easy substitution of different
output formats, including parse event stream equivalents. This makes heavy use of state information, so each method
call defined is only valid in certain states.
- Author:
- Dennis M. Sosnoski
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddOptionalTextAttribute(String name, String value) Add optional no-namespace text attribute to current open start tag.voidaddOptionalTextAttribute(String ns, String name, String value) Add optional text attribute to current open start tag.voidWrite a text value as the content of the current element.voidaddTextAttribute(String name, String value) Add no-namespace text attribute to current open start tag.voidaddTextAttribute(String ns, String name, String value) Add text attribute to current open start tag.voidclose()Close document output.voidconvert(boolean value) Write abooleanvalue to the current text selection.voidconvert(byte[] value) Write abyte[]value to the current text selection using base64Binary encoding.voidconvert(double value) Write adoublevalue to the current text selection.voidconvert(float value) Write afloatvalue to the current text selection.voidconvert(int value) Write anintvalue to the current text selection.voidconvert(long value) Write alongvalue to the current text selection.voidWrite aStringvalue to the current text selection.voidconvert(BigDecimal value) Write aBigDecimalvalue to the current text selection.voidconvert(BigInteger value) Write aBigIntegervalue to the current text selection.voidconvertDate(long value) Write alongmilliseconds time value to the current text selection as an xsd:date.voidconvertDateTime(long value) Write alongmilliseconds time value to the current text selection as an xsd:dateTime.voidconvertDateTime(long value, int nanos) Write alongmilliseconds time value and associated nanosecond count to the current text selection as an xsd:dateTime.voidconvertQName(String ns, String name) Write a qualified name value to the current text selection.voidconvertTime(long value) Write alongmilliseconds time value to the current text selection as an xsd:time.voidconvertTime(long value, int nanos) Write alongmilliseconds time value and associated nanosecond count to the current text selection as an xsd:time.voidendTag()Write end tag for current open element.voidflush()Flush document output.Get the marshalling context associated with this writer.String[][]Get extension namespace URIs added to those in mapping.intGet the number of namespaces currently defined.getNamespacePrefix(int index) Get current prefix defined for namespace.String[]Get namespace URIs for mapping.getNamespaceUri(int index) Get URI for namespace.intGet the current element nesting depth.intgetPrefixIndex(String prefix) Get index of namespace mapped to prefix.Get the current validation context for this writer.voidhandleMissingAttribute(String name) Handle a missing required attribute value from the implicit namespace in the generated document.voidhandleMissingAttribute(String ns, String name) Handle a missing required attribute value in the generated document.voidhandleMissingElement(String name) Handle a missing required element value from the implicit namespace in the generated document.voidhandleMissingElement(String ns, String name) Handle a missing required element value in the generated document.voidindent()Request output indent.voidopenNamespace(String ns, String prefix) Add a namespace declaration to the next element start tag.int[]openNamespaces(int[] nums, String[] prefs) Open the specified namespaces for use.voidRemove extension namespace URIs.voidpushExtensionNamespaces(String[] uris) Append extension namespace URIs to those in mapping.voidreset()Reset to initial state for reuse.voidselectAttribute(String name) Select a no-namespace attribute as the destination for a conversion.voidselectAttribute(String ns, String name) Select an attribute as the destination for a conversion.voidSelect text content as the destination for a conversion.voidselectContent(String name) Select a child element in the implicit namespace as the destination for a conversion.voidselectContent(String ns, String name) Select a child element as the destination for a conversion.voidsetAttributeDoubleQuote(boolean prefdbl) Set attribute double-quote character usage.voidsetBooleanNumeric(boolean prefnum) Set boolean numeric value usage.Set the implicit namespace used for elements unless otherwise specified.voidSet nesting indentation.voidWrite the start tag for an element in the implicit namespace.voidWrite the start tag for an element.voidstartTagImplicit(String ns, String prefix, String name) Declare a namespace, make it the implicit namespace, and write the start tag for an element in that namespace.voidwriteCData(String text) Write CDATA text to document.voidwriteComment(String text) Write comment to document.voidwriteDocType(String name, String sys, String pub, String subset) Write DOCTYPE declaration to document.voidwriteEntityRef(String name) Write entity reference to document.voidWrite processing instruction to document.voidwriteTextContent(String text) Write ordinary character data text content to document.voidwriteXMLDecl(String version, String encoding, String standalone) Write XML declaration to document.
-
Method Details
-
getContext
MarshallingContext getContext()Get the marshalling context associated with this writer. The marshalling context tracks higher-level information about the conversion of XML into a Java object structure.- Returns:
- context
-
getValidationContext
ValidationContext getValidationContext()Get the current validation context for this writer. The validation context is used both for tracking problems, and to determine the appropriate handling when a problem occurs.- Returns:
- context
-
getNestingDepth
int getNestingDepth()Get the current element nesting depth. Elements are only counted in the depth returned when they're officially open - after the start tag has been output and before the end tag has been output.- Returns:
- number of nested elements at current point in output
-
getNamespaceCount
int getNamespaceCount()Get the number of namespaces currently defined. This is equivalent to the index of the next extension namespace added.- Returns:
- namespace count
-
setIndent
Set nesting indentation. This is advisory only, and implementations of this interface are free to ignore it. The intent is to indicate that the generated output should use indenting to illustrate element nesting.- Parameters:
count- number of character to indent per level, or disable indentation if negative (zero means new line only)newline- sequence of characters used for a line ending (nullmeans use the single character '\n')indent- whitespace character used for indentation
-
setAttributeDoubleQuote
void setAttributeDoubleQuote(boolean prefdbl) Set attribute double-quote character usage. If this istrue, the double-quote (") character is preferred for attribute values; iffalse(the default), the single-quote (') character is preferred. This setting is advisory only, and implementations of this interface are free to ignore it.- Parameters:
prefdbl- prefer double-quote flag
-
setBooleanNumeric
void setBooleanNumeric(boolean prefnum) Set boolean numeric value usage. If this istrue, numeric values ('0' and '1') are preferred for boolean values; iffalse(the default), text values ('false' and 'true') are preferred. This setting is advisory only, and implementations of this interface are free to ignore it.- Parameters:
prefnum- prefer numeric boolean value flag
-
setImplicitNamespace
Set the implicit namespace used for elements unless otherwise specified. The namespace must have been opened prior to this call.- Parameters:
ns- namespace URI for element (may be the empty string for the no-namespace namespace)- Returns:
- prior implicit namespace
-
startTag
Write the start tag for an element in the implicit namespace.- Parameters:
name- element name- Throws:
JiBXException- on unrecoverable error
-
startTag
Write the start tag for an element.- Parameters:
ns- namespace URI for element (may be the empty string for the no-namespace namespace)name- unqualified element name- Throws:
JiBXException- on unrecoverable error
-
startTagImplicit
Declare a namespace, make it the implicit namespace, and write the start tag for an element in that namespace. This is just a shortcut for the sequence of callsopenNamespace(String, String),setImplicitNamespace(String),startTag(String).- Parameters:
ns- namespace URI for element (may be the empty string for the no-namespace namespace)prefix- prefix to be used for the namespace (use "" for default namespace declaration)name- unqualified element name- Throws:
JiBXException- on unrecoverable error
-
openNamespace
Add a namespace declaration to the next element start tag. If the namespace is already open this call does nothing.- Parameters:
ns- namespace URI (may be the empty string for the no-namespace namespace)prefix- prefix to be used for the namespace (use "" for default namespace declaration)- Throws:
JiBXException- on unrecoverable error
-
addTextAttribute
Add no-namespace text attribute to current open start tag. This is only valid with an open start tag.- Parameters:
name- unqualified attribute namevalue- text value for attribute- Throws:
JiBXException- on unrecoverable error
-
addTextAttribute
Add text attribute to current open start tag. This is only valid with an open start tag.- Parameters:
ns- namespace URI (may be the empty string for the no-namespace namespace)name- unqualified attribute namevalue- text value for attribute- Throws:
JiBXException- on unrecoverable error
-
addOptionalTextAttribute
Add optional no-namespace text attribute to current open start tag. This is only valid with an open start tag.- Parameters:
name- unqualified attribute namevalue- text value for attribute (nullif no value)- Throws:
JiBXException- on unrecoverable error
-
addOptionalTextAttribute
Add optional text attribute to current open start tag. This is only valid with an open start tag.- Parameters:
ns- namespace URI (may be the empty string for the no-namespace namespace)name- unqualified attribute namevalue- text value for attribute (nullif no value)- Throws:
JiBXException- on unrecoverable error
-
selectContent
Select text content as the destination for a conversion.- Throws:
JiBXException- on unrecoverable error
-
selectContent
Select a child element in the implicit namespace as the destination for a conversion.- Parameters:
name- element name- Throws:
JiBXException- on unrecoverable error
-
selectContent
Select a child element as the destination for a conversion.- Parameters:
ns- namespace URI (may be the empty string for the no-namespace namespace)name- element name- Throws:
JiBXException- on unrecoverable error
-
selectAttribute
Select a no-namespace attribute as the destination for a conversion. This is only valid with an open start tag.- Parameters:
name- unqualified attribute name- Throws:
JiBXException- on unrecoverable error
-
selectAttribute
Select an attribute as the destination for a conversion. This is only valid with an open start tag.- Parameters:
ns- namespace URI (may be the empty string for the no-namespace namespace)name- unqualified attribute name- Throws:
JiBXException- on unrecoverable error
-
convert
Write aStringvalue to the current text selection.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convert
Write anintvalue to the current text selection.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convert
Write alongvalue to the current text selection.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convert
Write afloatvalue to the current text selection.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convert
Write adoublevalue to the current text selection.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convert
Write abooleanvalue to the current text selection.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convert
Write abyte[]value to the current text selection using base64Binary encoding.- Parameters:
value- attribute value- Throws:
JiBXException- on unrecoverable error
-
convertDateTime
Write alongmilliseconds time value to the current text selection as an xsd:dateTime.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convertDateTime
Write alongmilliseconds time value and associated nanosecond count to the current text selection as an xsd:dateTime.- Parameters:
value-nanos-- Throws:
JiBXException- on unrecoverable error
-
convertDate
Write alongmilliseconds time value to the current text selection as an xsd:date.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convertTime
Write alongmilliseconds time value to the current text selection as an xsd:time.- Parameters:
value-- Throws:
JiBXException- on unrecoverable error
-
convertTime
Write alongmilliseconds time value and associated nanosecond count to the current text selection as an xsd:time.- Parameters:
value-nanos-- Throws:
JiBXException- on unrecoverable error
-
convertQName
Write a qualified name value to the current text selection. The qualified name is presented as a pair consisting of namespace URI and local name in order to allow flexible use.- Parameters:
ns- namespace URI (empty string if no-namespace namespace)name- local name- Throws:
JiBXException- on unrecoverable error
-
convert
Write aBigDecimalvalue to the current text selection.- Parameters:
value- (non-null)- Throws:
JiBXException- on unrecoverable error
-
convert
Write aBigIntegervalue to the current text selection.- Parameters:
value- (non-null)- Throws:
JiBXException- on unrecoverable error
-
addText
Write a text value as the content of the current element. This writes the corresponding end tag after writing the value.- Parameters:
value- content value- Throws:
JiBXException- on unrecoverable error
-
endTag
Write end tag for current open element.- Throws:
JiBXException- on unrecoverable error
-
handleMissingElement
Handle a missing required element value from the implicit namespace in the generated document.- Parameters:
name-- Throws:
JiBXException- on unrecoverable error
-
handleMissingElement
Handle a missing required element value in the generated document.- Parameters:
ns-name-- Throws:
JiBXException- on unrecoverable error
-
handleMissingAttribute
Handle a missing required attribute value from the implicit namespace in the generated document.- Parameters:
name-- Throws:
JiBXException- on unrecoverable error
-
handleMissingAttribute
Handle a missing required attribute value in the generated document.- Parameters:
ns-name-- Throws:
JiBXException- on unrecoverable error
-
writeXMLDecl
Write XML declaration to document. This can only be called before any other methods in the interface are called.- Parameters:
version- XML version textencoding- text for encoding attribute (unspecified ifnull)standalone- text for standalone attribute (unspecified ifnull)- Throws:
JiBXException- on error writing to document
-
writeTextContent
Write ordinary character data text content to document.- Parameters:
text- content value text (must not benull)- Throws:
JiBXException- on error writing to document
-
writeCData
Write CDATA text to document.- Parameters:
text- content value text (must not benull)- Throws:
JiBXException- on error writing to document
-
writeComment
Write comment to document.- Parameters:
text- comment text (must not benull)- Throws:
JiBXException- on error writing to document
-
writeEntityRef
Write entity reference to document.- Parameters:
name- entity name (must not benull)- Throws:
JiBXException- on error writing to document
-
writeDocType
Write DOCTYPE declaration to document.- Parameters:
name- root element namesys- system ID (nullif none, must be non-nullfor ID to be used)pub- ID (nullif none)subset- internal subset (nullif none)- Throws:
JiBXException- on error writing to document
-
writePI
Write processing instruction to document.- Parameters:
target- processing instruction target name (must not benull)data- processing instruction data (must not benull)- Throws:
JiBXException- on error writing to document
-
indent
Request output indent. The writer implementation should normally indent output as appropriate. This method can be used to request indenting of output that might otherwise not be indented. The normal effect when used with a text-oriented writer should be to output the appropriate line end sequence followed by the appropriate number of indent characters for the current nesting level.- Throws:
JiBXException- on error writing to document
-
flush
Flush document output. Writes any buffered data to the output medium. This does not flush the output medium itself, only any internal buffering within the writer.- Throws:
JiBXException- on error writing to document
-
close
Close document output. Completes writing of document output, including flushing and closing the output medium.- Throws:
JiBXException- on error writing to document
-
reset
void reset()Reset to initial state for reuse. The context is serially reusable, as long as this method is called to clear any retained state information between uses. It is automatically called when output is set. -
getNamespaces
String[] getNamespaces()Get namespace URIs for mapping. This gets the full ordered array of namespaces known in the binding used for this marshalling, where the index number of each namespace URI is the namespace index used to lookup the prefix when marshalling a name in that namespace. The returned array must not be modified.- Returns:
- array of namespaces
-
getNamespaceUri
Get URI for namespace.- Parameters:
index- namespace URI index number- Returns:
- namespace URI text, or
nullif the namespace index is invalid
-
getNamespacePrefix
Get current prefix defined for namespace.- Parameters:
index- namespace URI index number- Returns:
- current prefix text, or
nullif the namespace is not currently mapped
-
getPrefixIndex
Get index of namespace mapped to prefix. This can be an expensive operation with time proportional to the number of namespaces defined, so it should be used with care.- Parameters:
prefix- text to match (non-null, use "" for default prefix)- Returns:
- index namespace URI index number mapped to prefix
-
pushExtensionNamespaces
Append extension namespace URIs to those in mapping.- Parameters:
uris- namespace URIs to extend those in mapping
-
popExtensionNamespaces
void popExtensionNamespaces()Remove extension namespace URIs. This removes the last set of extension namespaces pushed usingpushExtensionNamespaces(java.lang.String[]). -
getExtensionNamespaces
String[][] getExtensionNamespaces()Get extension namespace URIs added to those in mapping. This gets the current set of extension definitions. The returned arrays must not be modified.- Returns:
- array of arrays of extension namespaces (
nullif none)
-
openNamespaces
Open the specified namespaces for use. This method is normally only called internally, when namespace declarations are actually written to output. It is exposed as part of this interface to allow for special circumstances where namespaces are being written outside the usual processing. The namespaces will remain open for use until the current element is closed.- Parameters:
nums- array of namespace indexes defined by this element (must be constant, reference is kept until namespaces are closed)prefs- array of namespace prefixes mapped by this element (nonullvalues, use "" for default namespace declaration)- Returns:
- array of indexes for namespaces not previously active (the ones actually needing to be declared, in the case of text output)
- Throws:
JiBXException- on error writing to document
-