Skip to: Site menu | Main content

Woodstox

High-performance XML processor.

ConfiguringStreamWriters Print

Configuring Woodstox XMLStreamWriters

Woodstox writers have three kinds of configurable properties

  • ones defined by the StAX specification
  • ones added by Stax2 (v1.0)
  • ones added by Woodstox as implementation-dependant extensions.

StAX 1.0 specified properties

All property ids in this property group refer to constants defined in javax.xml.stream.XMLOutputFactory

  • IS_REPAIRING_NAMESPACES
    • Short desc: Enables/disables fully automatic handling of namespace bindings. See full description for details.
    • Type: java.lang.Boolean
    • Default value: False

Stax2 (v1.0) specified properties

All property ids in this property group refer to constants defined in org.codehaus.stax2.XMLOutputFactory2 .

  • P_AUTOMATIC_EMPTY_ELEMENTS
    • Short desc: Whether writer is allowed to output empty elements (like "<empty />") instead of separate start and end elements, in cases where element has no content. If set to true, writer can output empty elements (and with current implementation, will do so if possible). If set to false, will only output empty elements when specifically instructed to do so.
    • Type: java.lang.Boolean
    • Default value: True
  • P_NAMESPACE_AWARE
    • Short desc: Determines whether the writer instance is to handle namespaces or not; if not, a simpler (and slightly faster) instance can be constructed; otherwise a fully namespace-aware instance needs to be constructed. See full description for details.
    • Type: java.lang.Boolean
    • Default value: True
  • P_AUTOMATIC_NS_PREFIX
    • Short desc:
    • Type: java.lang.String
    • Default value: "wstxns"

String to use as the base of the prefix to use for automatically created namespace prefixes. To this base, a sequence number will be added to guarantee (local) uniqueness of the namespace prefix. Can be changed to any other String; care should be taken not to use illegal characters in the name (as per XML specs); Woodstox does not check for its validity.

  • P_TEXT_ESCAPER
    • Short desc:
    • Type: org.codehaus.stax.EscapingWriterFactory
    • Default value: null

If set, this factory is used to create "escaping Writers" to use when outputting XML text content, Such writers escape characters that either can not be expressed as (like '&ltl', '&' and '>' in some cases), but can also escape other characters. If not defined, the default escaping Writer is used; it knows how to do all necessary escapes – only define custom implementation if you want additional escaping.

  • P_ATTR_VALUE_ESCAPER
    • Short desc:
    • Type: org.codehaus.stax.EscapingWriterFactory
    • Default value: null

If set, this factory is used to create "escaping Writers" to use when

outputting XML attribute value text, Such writers escape characters that

either can not be expressed as (like '&ltl' and '&', and the quote

character used), but can also escape other

characters. If not defined, the default escaping Writer is used; it knows

how to do all necessary escapes – only define custom implementation if

you want additional escaping.

Woodstox custom properties

All property ids in this property group refer to constants defined in com.ctc.wstx.api.WstxOutputProperties .

Note, also, that in some cases there may be more detailed information available about specific properties in com.ctc.wstx.stax.WstxOutputFactory JavaDocs .

  • P_OUTPUT_CDATA_AS_TEXT
    • Short desc:
    • Type: java.lang.Boolean
    • Default value: False

Whether writer is to output all text as CHARACTERS; even when using CData output methods.

If set to true, writer should never produce CDATA output; instead, all text should be output as properly encoded text.

If set to false, output is done based on methods called.

Turning this feature on may be useful when output should never have CDATA sections (gets processed by simpler code than full XML parsers, for example), but where external code is used to output XML (but factories are controlled by application).

  • P_COPY_DEFAULT_ATTRS
    • Short desc:
    • Type: java.lang.Boolean
    • Default value: False
  • P_OUTPUT_VALIDATE_STRUCTURE
    • Short desc: Whether writer is allowed to verify that the output structure (order and nesting of elements) resulting from a call sequence would result in non-well-formed output, and if so, to throw a stream exception.
    • Type: java.lang.Boolean
    • Default value: True

If set to true, writer is allowed to check the structure; if false, it

is to output it as is.

There is some performance overhead when enabling this feature,

but it is generally negligible.

  • P_OUTPUT_VALIDATE_CONTENT
    • Short desc: Whether writer is allowed to verify that the textual content output as part of most events (text segments, CDATA sections, processing instruction data, comment contents, element names) can be verified so it would not

      contain illegal characters or character combinations, and if so,

      to throw a stream exception.
    • Type: java.lang.Boolean
    • Default value: False

If set to true, writer is allowed to check the content; if false, it is to output it as is.

An example of illegal content would be comments content that contains

character sequence '--', or processing instruction with sequence '?>'.

There is some performance overhead when enabling this feature, depending

on type of content output (comment and processing instruction content

checked).

  • P_OUTPUT_VALIDATE_ATTR
    • Short desc: False
    • Type: java.lang.Boolean
    • Default value:Whether writer is allowed to verify that the attribute values to output would be valid; and in case of problem to throw a stream exception. If set to true, writer is allowed to check the attributes and their content (for things like potential duplication); if false, to output attribute as is without checks.
  • P_OUTPUT_VALIDATE_NAMES
    • Short desc: False
    • Type: java.lang.Boolean
    • Default value:
  • P_OUTPUT_FIX_CONTENT
    • Short desc: False
    • Type: java.lang.Boolean
    • Default value:

Property groups ("profiles")

In addition to being able to set individual values separate, Woodstox also allows for using "profiles"; pre-set values for group of properties to optimize readers for specific goal.

To use profiles, you need to use Woodstox-specific method calls, since StAX API does not have similar concept.

As with Woodstox-specific properties, in some cases there may be more detailed information available about specific profiles in com.ctc.wstx.stax.WstxOutputFactory JavaDocs .

  • configureForMaxValidation()

Profile that will try to maximize checks done, to try to prevent output of non-well-formed or invalid XML. This will impose some overhead on performance.

Will set following property values:

  • P_OUTPUT_VALIDATE_ATTR: True
  • P_OUTPUT_VALIDATE_CONTENT: True
  • P_OUTPUT_VALIDATE_NS: True
  • P_OUTPUT_VALIDATE_STRUCTURE: True
  • configureForMinValidation()

Profile that will try minimize checks done ("I know what I am doing!"), and effectively remove checking overhead. This also improves performance, compared to full validation tests.

Will set following property values:

P_OUTPUT_VALIDATE_ATTR: False

P_OUTPUT_VALIDATE_CONTENT: False

P_OUTPUT_VALIDATE_NS: False

P_OUTPUT_VALIDATE_STRUCTURE: False