Class NSUtils


  • public final class NSUtils
    extends Object
    Contains utility methods to work with XML namespaces.
    • Method Detail

      • generatePrefix

        public static String generatePrefix​(String namespaceURI)
        Generate a namespace prefix for the given namespace URI. The generated prefix is based on a hash of the namespace URI. This implies that a given namespace URI is always mapped to the same prefix and that there is no guarantee that the generated prefixes are unique. However, the likelihood of a (accidental) collisions is very small.

        Using hash based prefixes has the advantage of reducing the number of entries created in the symbol table of the parser on the receiving side, assuming that the symbol table is reused to parse multiple documents (which is a common optimization).

        Parameters:
        namespaceURI - the namespace URI to generate a prefix for; must not be null
        Returns:
        the generated prefix