Interface NamespaceContext


public interface NamespaceContext
Represents an interface to query namespace information.

The prefix and namespace must be identical references for equal strings, thus each string should be internalized (@see String.intern()) or added to the SymbolTable

Version:
$Id: NamespaceContext.java 447247 2006-09-18 05:23:52Z mrglavas $
Author:
Andy Clark, IBM
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The XML Namespace ("http://www.w3.org/XML/1998/namespace").
    static final String
    XML Information Set REC all namespace attributes (including those named xmlns, whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    declarePrefix(String prefix, String uri)
    Declare a Namespace prefix.
    Return an enumeration of all prefixes whose declarations are active in the current context.
    Returns the prefix at the specified index in the current context.
    int
    Return a count of locally declared prefixes, including the default prefix if bound.
    Look up a namespace URI and get one of the mapped prefix.
    getURI(String prefix)
    Look up a prefix and get the currently-mapped Namespace URI.
    void
    Revert to the previous Namespace context.
    void
    Start a new Namespace context.
    void
    Reset this Namespace support object for reuse.
  • Field Details

    • XML_URI

      static final String XML_URI
      The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is the Namespace URI that is automatically mapped to the "xml" prefix.
    • XMLNS_URI

      static final String XMLNS_URI
      XML Information Set REC all namespace attributes (including those named xmlns, whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
  • Method Details

    • pushContext

      void pushContext()
      Start a new Namespace context.

      A new context should be pushed at the beginning of each XML element: the new context will automatically inherit the declarations of its parent context, but it will also keep track of which declarations were made within this context.

      See Also:
    • popContext

      void popContext()
      Revert to the previous Namespace context.

      The context should be popped at the end of each XML element. After popping the context, all Namespace prefix mappings that were previously in force are restored.

      Users must not attempt to declare additional Namespace prefixes after popping a context, unless you push another context first.

      See Also:
    • declarePrefix

      boolean declarePrefix(String prefix, String uri)
      Declare a Namespace prefix.

      This method declares a prefix in the current Namespace context; the prefix will remain in force until this context is popped, unless it is shadowed in a descendant context.

      Note that to declare a default Namespace, use the empty string. The prefixes "xml" and "xmlns" can't be rebound.

      Note that you must not declare a prefix after you've pushed and popped another Namespace.

      Parameters:
      prefix - The prefix to declare, or null for the empty string.
      uri - The Namespace URI to associate with the prefix.
      Returns:
      true if the prefix was legal, false otherwise
      See Also:
    • getURI

      String getURI(String prefix)
      Look up a prefix and get the currently-mapped Namespace URI.

      This method looks up the prefix in the current context. If no mapping is found, this methods will continue lookup in the parent context(s). Use the empty string ("") for the default Namespace.

      Parameters:
      prefix - The prefix to look up.
      Returns:
      The associated Namespace URI, or null if the prefix is undeclared in this context.
    • getPrefix

      String getPrefix(String uri)
      Look up a namespace URI and get one of the mapped prefix.

      This method looks up the namespace URI in the current context. If more than one prefix is currently mapped to the same URI, this method will make an arbitrary selection If no mapping is found, this methods will continue lookup in the parent context(s).

      Parameters:
      uri - The namespace URI to look up.
      Returns:
      One of the associated prefixes, or null if the uri does not map to any prefix.
      See Also:
    • getDeclaredPrefixCount

      int getDeclaredPrefixCount()
      Return a count of locally declared prefixes, including the default prefix if bound.
    • getDeclaredPrefixAt

      String getDeclaredPrefixAt(int index)
      Returns the prefix at the specified index in the current context.
    • getAllPrefixes

      Enumeration getAllPrefixes()
      Return an enumeration of all prefixes whose declarations are active in the current context. This includes declarations from parent contexts that have not been overridden.
      Returns:
      Enumeration
    • reset

      void reset()
      Reset this Namespace support object for reuse.

      It is necessary to invoke this method before reusing the Namespace support object for a new session.

      Note that implementations of this method need to ensure that the declaration of the prefixes "xmlns" and "xml" are available.