Class XmlNameProcessors

    • Method Detail

      • newPassthroughProcessor

        public static XmlNameProcessor newPassthroughProcessor()
        Generates a new processor that does nothing and just passes through the names as-is. Using this processor may generate invalid XML.

        With this processor set, a map with the keys "123" and "$ I am <fancy>! &;" will be written as:

        
         <DTO>
             <badMap>
                 <$ I am <fancy>! &;>xyz</$ I am <fancy>! &;>
                 <123>bar</123>
             </badMap>
         </DTO>
         

        This is the default behavior for backwards compatibility.

        Since:
        2.14
      • newReplacementProcessor

        public static XmlNameProcessor newReplacementProcessor​(java.lang.String replacement)
        Generates a new processor that replaces all characters that are NOT one of:
        • Lower- or upper-case ASCII letter (a to z, A to Z)
        • Digit (0 to 9) in position OTHER than the first character
        • Underscore
        • Hyphen (-) in position OTHER than the first character
        • Colon (only exposed if underlying parser is in non-namespace-aware mode)
        in an XML name with a replacement string. This is a one-way processor, since there is no way to reverse this replacement step.

        With this processor set (and "_" as the replacement string), a map with the keys "123" and "$ I am <fancy>! &;" will be written as:

        NOTE: this processor works for US-ASCII based element and attribute names but is unlikely to work well for many "international" use cases.

        
         <DTO>
             <badMap>
                 <__I_am__fancy_____>xyz</__I_am__fancy_____>
                 <_23>bar</_23>
             </badMap>
         </DTO>
         
        Parameters:
        replacement - The replacement string to replace invalid characters with
        Since:
        2.14
      • newBase64Processor

        public static XmlNameProcessor newBase64Processor​(java.lang.String prefix)
        Generates a new processor that escapes all names that contains characters OTHER than following characters:
        • Lower- or upper-case ASCII letter (a to z, A to Z)
        • Digit (0 to 9) in position OTHER than the first characters
        • Underscore
        • Hyphen (-) in position OTHER than the first character
        • Colon (only exposed if underlying parser is in non-namespace-aware mode)
        with a base64-encoded version. Here the base64url encoder and decoders are used. The = padding characters are always omitted.

        With this processor set, a map with the keys "123" and "$ I am <fancy>! &;" will be written as:

        
         <DTO>
             <badMap>
                 <base64_tag_JCBJIGFtIDxmYW5jeT4hICY7>xyz</base64_tag_JCBJIGFtIDxmYW5jeT4hICY7>
                 <base64_tag_MTIz>bar</base64_tag_MTIz>
             </badMap>
         </DTO>
         

        NOTE: you must ensure that no incoming element or attribute name starts with prefix, otherwise decoding will not work.

        Parameters:
        prefix - The prefix to use for name that are escaped
        Since:
        2.14
      • newAlwaysOnBase64Processor

        public static XmlNameProcessor newAlwaysOnBase64Processor()
        Similar to newBase64Processor(String), however, names will always be escaped with base64. No magic prefix is required for this case, since adding one would be redundant because all names will be base64 encoded.