Class XMLWriterSettings

    • Field Detail

      • DEFAULT_XML_SERIALIZE_VERSION

        public static final EXMLSerializeVersion DEFAULT_XML_SERIALIZE_VERSION
        Default default XML version is 1.0
      • DEFAULT_SERIALIZE_XML_DECLARATION

        public static final EXMLSerializeXMLDeclaration DEFAULT_SERIALIZE_XML_DECLARATION
        By default all fields of the XML declaration are emitted
      • DEFAULT_NEW_LINE_AFTER_XML_DECLARATION

        public static final boolean DEFAULT_NEW_LINE_AFTER_XML_DECLARATION
        By default a newline character is emitted afterwards
        See Also:
        Constant Field Values
      • DEFAULT_SERIALIZE_DOC_TYPE

        public static final EXMLSerializeDocType DEFAULT_SERIALIZE_DOC_TYPE
        By default the document type is emitted
      • DEFAULT_SERIALIZE_COMMENTS

        public static final EXMLSerializeComments DEFAULT_SERIALIZE_COMMENTS
        By default comments are emitted
      • DEFAULT_SERIALIZE_INDENT

        public static final EXMLSerializeIndent DEFAULT_SERIALIZE_INDENT
        By default the output is indented and aligned (newlines are added)
      • DEFAULT_INCORRECT_CHARACTER_HANDLING

        public static final EXMLIncorrectCharacterHandling DEFAULT_INCORRECT_CHARACTER_HANDLING
        By default invalid characters are not written and a log message is emitted
      • DEFAULT_XML_CHARSET_OBJ

        public static final Charset DEFAULT_XML_CHARSET_OBJ
        The default charset is UTF-8
      • DEFAULT_XML_CHARSET

        public static final String DEFAULT_XML_CHARSET
        The default charset is UTF-8
      • DEFAULT_USE_DOUBLE_QUOTES_FOR_ATTRIBUTES

        public static final boolean DEFAULT_USE_DOUBLE_QUOTES_FOR_ATTRIBUTES
        By default double quotes are used to wrap attribute values
        See Also:
        Constant Field Values
      • DEFAULT_SPACE_ON_SELF_CLOSED_ELEMENT

        public static final boolean DEFAULT_SPACE_ON_SELF_CLOSED_ELEMENT
        By default a leading space is inserted before a self closed element (e.g. <b /> in contrast to <b/>).
        See Also:
        Constant Field Values
      • DEFAULT_INDENTATION_STRING

        public static final String DEFAULT_INDENTATION_STRING
        By default indentation happens with 2 spaces
        See Also:
        Constant Field Values
      • DEFAULT_EMIT_NAMESPACES

        public static final boolean DEFAULT_EMIT_NAMESPACES
        By default namespaces are written.
        See Also:
        Constant Field Values
      • DEFAULT_PUT_NAMESPACE_CONTEXT_PREFIXES_IN_ROOT

        public static final boolean DEFAULT_PUT_NAMESPACE_CONTEXT_PREFIXES_IN_ROOT
        By default namespace context prefixes are put inside the root element
        See Also:
        Constant Field Values
      • DEFAULT_WRITE_CDATA_AS_TEXT

        public static final boolean DEFAULT_WRITE_CDATA_AS_TEXT
        By default CDATA children are emitted as CDATA
        See Also:
        Constant Field Values
      • DEFAULT_ORDER_ATTRIBUTES_AND_NAMESPACES

        public static final boolean DEFAULT_ORDER_ATTRIBUTES_AND_NAMESPACES
        By default the insertion order of attributes is maintained
        See Also:
        Constant Field Values
      • DEFAULT_XML_SETTINGS

        public static final IXMLWriterSettings DEFAULT_XML_SETTINGS
        The default settings to use - last constant
    • Constructor Detail

      • XMLWriterSettings

        public XMLWriterSettings()
        Creates a default settings object with the following settings:
        • XML version 1.0
        • with XML declaration
        • with document type
        • with comments
        • Indented and aligned
        • Writing invalid characters to the file as is - may result in invalid XML files
        • Default character set UTF-8
        • No namespace context
      • XMLWriterSettings

        public XMLWriterSettings​(@Nonnull
                                 IXMLWriterSettings aOther)
        Copy constructor.
        Parameters:
        aOther - The object to copy the settings from. May not be null.
    • Method Detail

      • isNewLineAfterXMLDeclaration

        public boolean isNewLineAfterXMLDeclaration()
        Specified by:
        isNewLineAfterXMLDeclaration in interface IXMLWriterSettings
        Returns:
        true if a newline should be added after the XML declaration or not. Defaults to true.
      • setNewLineAfterXMLDeclaration

        @Nonnull
        public final XMLWriterSettings setNewLineAfterXMLDeclaration​(boolean bNewLineAfterXMLDeclaration)
        Change whether a newline should be printed after the XML declaration or not.
        Parameters:
        bNewLineAfterXMLDeclaration - true to print it, false to not print a new line.
        Returns:
        this for chaining
      • setSerializeComments

        @Nonnull
        public final XMLWriterSettings setSerializeComments​(@Nonnull
                                                            EXMLSerializeComments eSerializeComments)
        Set the way how comments should be handled.
        Parameters:
        eSerializeComments - The comment handling. May not be null.
        Returns:
        this
      • setIndentDeterminator

        @Nonnull
        public final XMLWriterSettings setIndentDeterminator​(@Nonnull
                                                             IXMLIndentDeterminator aIndentDeterminator)
        Set the dynamic (per-element) indent determinator to be used.
        Parameters:
        aIndentDeterminator - The object to use. May not be null.
        Returns:
        this
      • setIncorrectCharacterHandling

        @Nonnull
        public final XMLWriterSettings setIncorrectCharacterHandling​(@Nonnull
                                                                     EXMLIncorrectCharacterHandling eIncorrectCharacterHandling)
        Set the way how to handle invalid characters.
        Parameters:
        eIncorrectCharacterHandling - The invalid character handling. May not be null.
        Returns:
        this
      • setCharset

        @Nonnull
        public final XMLWriterSettings setCharset​(@Nonnull
                                                  Charset aCharset)
        Set the serialization charset.
        Parameters:
        aCharset - The charset to be used. May not be null.
        Returns:
        this
      • setNamespaceContext

        @Nonnull
        public final XMLWriterSettings setNamespaceContext​(@Nullable
                                                           INamespaceContext aNamespaceContext)
        Set the namespace context to be used.
        Parameters:
        aNamespaceContext - The namespace context to be used. May be null.
        Returns:
        this
      • isUseDoubleQuotesForAttributes

        public boolean isUseDoubleQuotesForAttributes()
        Specified by:
        isUseDoubleQuotesForAttributes in interface IXMLWriterSettings
        Returns:
        true if attribute values should be enclosed in double quotes, false if single quotes should be used.
      • setUseDoubleQuotesForAttributes

        @Nonnull
        public final XMLWriterSettings setUseDoubleQuotesForAttributes​(boolean bUseDoubleQuotesForAttributes)
      • isSpaceOnSelfClosedElement

        public boolean isSpaceOnSelfClosedElement()
        Description copied from interface: IXMLWriterSettings
        Determine if a self closed element (an element having no children) should be emitted with a space at the end (<br />) or not ( <br/>)
        Specified by:
        isSpaceOnSelfClosedElement in interface IXMLWriterSettings
        Returns:
        true if a space should be emitted, false if no space should be emitted.
      • setSpaceOnSelfClosedElement

        @Nonnull
        public final XMLWriterSettings setSpaceOnSelfClosedElement​(boolean bSpaceOnSelfClosedElement)
      • getNewLineMode

        @Nonnull
        public com.helger.commons.system.ENewLineMode getNewLineMode()
        Specified by:
        getNewLineMode in interface IXMLWriterSettings
        Returns:
        The newline mode to be used. By default it is the platform specific new line mode. Never null.
      • isEmitNamespaces

        public boolean isEmitNamespaces()
        Description copied from interface: IXMLWriterSettings
        Determine if namespaces should be emitted or not.
        Specified by:
        isEmitNamespaces in interface IXMLWriterSettings
        Returns:
        true if namespaces should be emitted, false if all created elements should reside in the default namespace.
      • isPutNamespaceContextPrefixesInRoot

        public boolean isPutNamespaceContextPrefixesInRoot()
        Description copied from interface: IXMLWriterSettings
        Check if the flag for putting all namespace prefixes specified in the namespace context should be put in the root document. This setting only has an effect if a namespace context is defined and if it implements the IIterableNamespaceContext interface!
        Specified by:
        isPutNamespaceContextPrefixesInRoot in interface IXMLWriterSettings
        Returns:
        true if it is enabled, false if not.
      • setPutNamespaceContextPrefixesInRoot

        @Nonnull
        public final XMLWriterSettings setPutNamespaceContextPrefixesInRoot​(boolean bPutNamespaceContextPrefixesInRoot)
      • isWriteCDATAAsText

        public boolean isWriteCDATAAsText()
        Description copied from interface: IXMLWriterSettings
        Check if all CDATA children should be emitted as normal text or not. This is required for XML canonicalization.
        Specified by:
        isWriteCDATAAsText in interface IXMLWriterSettings
        Returns:
        true if CDATA should be written as text, false to keep CDATA as it is.
      • isOrderAttributesAndNamespaces

        public boolean isOrderAttributesAndNamespaces()
        Description copied from interface: IXMLWriterSettings
        Determine if attributes of elements and namespaces should be emitted in alphabetical order or not. This is required for XML canonicalization.
        Specified by:
        isOrderAttributesAndNamespaces in interface IXMLWriterSettings
        Returns:
        true to order attributes, false to keep the original order.
      • setOrderAttributesAndNamespaces

        @Nonnull
        public final XMLWriterSettings setOrderAttributesAndNamespaces​(boolean bOrderAttributesAndNamespaces)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • createForCanonicalization

        @Nonnull
        @ReturnsMutableCopy
        public static XMLWriterSettings createForCanonicalization()
        The canonical form of an XML document is physical representation of the document produced by the method described in this specification. The changes are summarized in the following list:
        • The document is encoded in UTF-8
        • Line breaks normalized to #xA on input, before parsing
        • Attribute values are normalized, as if by a validating processor
        • Character and parsed entity references are replaced
        • CDATA sections are replaced with their character content
        • The XML declaration and document type declaration are removed
        • Empty elements are converted to start-end tag pairs
        • Whitespace outside of the document element and within start and end tags is normalized
        • All whitespace in character content is retained (excluding characters removed during line feed normalization)
        • Attribute value delimiters are set to quotation marks (double quotes)
        • Special characters in attribute values and character content are replaced by character references
        • Superfluous namespace declarations are removed from each element
        • Default attributes are added to each element
        • Fixup of xml:base attributes [C14N-Issues] is performed
        • Lexicographic order is imposed on the namespace declarations and attributes of each element
        Returns:
        XMLWriterSettings for canonicalization