Class NSContextManager

  • All Implemented Interfaces:
    NamespaceContext

    public class NSContextManager
    extends Object
    implements NamespaceContext
    Helper class to manage XML namespaces. The reserved xml and xmlns prefixes are hard-coded.

    The following namespaces are pre-defined:

    • xml : http://www.w3.org/XML/1998/namespace
    • xmlns : http://www.w3.org/2000/xmlns/
    • xsl : http://www.w3.org/1999/XSL/Transform
    • Constructor Detail

      • NSContextManager

        public NSContextManager()
        Creates a new NSContextManager object.
    • Method Detail

      • getNamespaceURI

        public String getNamespaceURI​(String prefix)
        Gets the namespace URI for a given prefix.
        Specified by:
        getNamespaceURI in interface NamespaceContext
        Parameters:
        prefix - The prefix to look up.
        Returns:
        The namespace URI for the given prefix, or XMLConstants.NULL_NS_URI if none was found.
      • getPrefix

        public String getPrefix​(String uri)
        Gets the prefix for a given namespace URI.
        Specified by:
        getPrefix in interface NamespaceContext
        Parameters:
        uri - The namespace URI to look up.
        Returns:
        The prefix for the given namespace URI, or null the mamager has no such namespace URI defined.
      • add

        public void add​(String prefix,
                        String uri)
        Adds a prefix/uri pair to the manager. No checking is done for existing prefix: If the same is already defined, it will be overwritten.
        Parameters:
        prefix - The prefix of the namespace
        uri - The uri of the namespace