javax.xml.namespace
Interface NamespaceContext


public interface NamespaceContext

The NamespaceContext interface is a helper tool for XML parsing applications which need to know the mappings between XML namespace prefixes and namespace URI's. As such, it is closely related to the events org.xml.sax.ContentHandler#startPrefixMapping(String,String), and org.xml.sax.ContentHandler#endPrefixMapping(String) in org.xml.sax.ContentHandler.

In what follows, it is important to note, that a single prefix can only be mapped to a single namespace URI at any time. However, the converse is not true: Multiple prefixes can be mapped to the same namespace URI's.

For example, in the case of an XML Schema parser, an instance of NamespaceContext might be used to resolve the namespace URI's of referenced data types, and element or attribute names, which are typically given as qualified names, including a prefix and a local name.

Since:
JAXB 1.0
Author:
JSR-31

Method Summary
 java.lang.String getNamespaceURI(java.lang.String pPrefix)
          Given a prefix, returns the namespace URI associated with the prefix.
 java.lang.String getPrefix(java.lang.String pNamespaceURI)
          This method returns a prefix, which is currently mapped to the given namespace URI.
 java.util.Iterator getPrefixes(java.lang.String pNamespaceURI)
          This method returns a collection of prefixes, which are currently mapped to the given namespace URI.
 

Method Detail

getNamespaceURI

java.lang.String getNamespaceURI(java.lang.String pPrefix)

Given a prefix, returns the namespace URI associated with the prefix. More precisely, the following rules apply:

Prefix (Input)Namespace URI (Output)
XMLConstants.DEFAULT_NS_PREFIX ("") The current default namespace URI or null, if there is no such default. (In which case the absence of a prefix indicates the absence of a namespace URI.)
XMLConstants.XML_NS_PREFIX ("xml") XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace")
XMLConstants.XMLNS_ATTRIBUTE ("xmlns") XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/")
Any other prefixThe namespace URI currently mapped to the prefix or null, if no such mapping is established.

Parameters:
pPrefix - The prefix being looked up in the list of mappings.
Returns:
The Namespace URI to which the input prefix is currently mapped or null, if there is no such mapping.
Throws:
java.lang.IllegalArgumentException - The input prefix is null.

getPrefix

java.lang.String getPrefix(java.lang.String pNamespaceURI)

This method returns a prefix, which is currently mapped to the given namespace URI. Note, that multiple prefixes may be mapped to the namespace URI, in which case the returned prefix is undetermined. Do not make any assumptions on the order in such cases. It is a better choice to use getPrefixes(String) instead, if you depend on some order

Namespace URI (Input)Prefix (Output)
Current default namespace URI XMLConstants.DEFAULT_NS_PREFIX ("")
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") XMLConstants.XMLNS_ATTRIBUTE

Parameters:
pNamespaceURI - The namespace URI being looked up in the list of mappings.
Returns:
A prefix currently mapped to the given namespace URI or null, if there is no such mapping
Throws:
java.lang.IllegalArgumentException - The input URI is null

getPrefixes

java.util.Iterator getPrefixes(java.lang.String pNamespaceURI)

This method returns a collection of prefixes, which are currently mapped to the given namespace URI. Note, that the collection may contain more than one prefix, in which case the order is undetermined. If you do not depend on a certain order and any prefix will do, you may choose to use getPrefix(String) instead. The following table describes the returned values in more details:

Namespace URI (Input)Prefix collection (Output)
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") Collection with a single element: XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") Collection with a single element: XMLConstants.XMLNS_ATTRIBUTE

Parameters:
pNamespaceURI - The namespace URI being looked up in the list of mappings or null, if there is no such mapping.
Returns:
An unmodifiable Iterator: Using it's Iterator.remove() method throws an UnsupportedOperationException.
Throws:
java.lang.IllegalStateException - The input URI is null


Copyright © 2005-2006 Apache Software Foundation. All Rights Reserved.