javax.xml.namespace
Class QName

java.lang.Object
  extended by javax.xml.namespace.QName

public class QName
extends Object

XML namespaces provide a way to distinguish determiniscally between XML elements that have the same local name but are, in fact, from different vocabularies. This is done by associating an element with a namespace. A namespace acts as a scope for all elements associated with it. Namespaces themselves also have names. A namespace name is a uniform resource identifier (URI). Such a URI serves as a unique string, and needs not be able to be dereferenced. The namespace name and the local name of the element together form a globally unique name known as a qualified name.

Namespace declarations appear inside an element start tag and are used to map a namespace name to another, typically shorter, string known as a namespace prefix. The syntax for a namespace declaration is xmlns:prefix='URI'. It is also possible to map a namespace name to no prefix using a default namespace declaration. The syntax for a default namespace declaration is xmlns='URI'. Only one default namespace declaration may appear on an element. Any number of nondefault namespace declarations may appear on an element, provided they all have different prefix parts.

The names of all elements in a document that conforms to the Namespaces in the XML specification are QName. Syntactically, all QNames have a local name and an optional prefix. Both the local name and the prefix are NCNames. An NCName is a name without a colon in it.

Elements not in any namespace are known as unqualified elements.

Since:
BlackBerry API 4.3.0

Constructor Summary
QName(String localName)
          Constructs a QName object given the local name.
QName(String namespaceURI, String localName)
           Constructs a QName object given the Namespace URI, and the local name.
QName(String namespaceURI, String localName, String prefix)
           Constructs a QName object given the Namespace URI, the local name, and the prefix.
 
Method Summary
 boolean equals(Object anObject)
           Equality testing for QNames.
 String getLocalPart()
           Retrieves the local name of this QName.
 String getNamespaceURI()
           Retrieves the Namespace URI of this QName.
 String getPrefix()
           Retrieves the prefix of this QName.
 int hashCode()
           Generates the hash code for this QName.
 String toString()
           Returns a String representation of this QName.
static QName valueOf(String aString)
           Given the string representation of a QName, constructs the QName with the prefix being set to the empty string.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 



Constructor Detail

QName

public QName(String namespaceURI,
             String localName,
             String prefix)

Constructs a QName object given the Namespace URI, the local name, and the prefix. If the Namespace URI is null, it is set to "". (The namespace name of unqualified elements is the empty string "". If a default namespace declaration is in scope and an unqualified element is required, the default namespace declaration can be masked by providing a namespace declaration of the form xmlns="" on the element.)

Note: Use "" to indicate that a prefix is either not present or not relevant.

Parameters:
namespaceURI - the namespace URI of this QName.
localName - the local name of this QName.
prefix - the prefix of this QName.
Throws:
IllegalArgumentException - if the local name is null or it is of length 0; or if the prefix is null.
Since:
BlackBerry API 4.3.0

QName

public QName(String namespaceURI,
             String localName)

Constructs a QName object given the Namespace URI, and the local name.

The prefix is set to the empty string "" (for default namespace).

Parameters:
namespaceURI - the namespace URI of this QName.
localName - the local name of this QName.
Since:
BlackBerry API 4.3.0

QName

public QName(String localName)
Constructs a QName object given the local name. The namespace URI is set to the empty string "" (for unqualified elements); the prefix is set to the empty string "" (for default namespace).

Parameters:
localName - the local name of this QName.
Since:
BlackBerry API 4.3.0


Method Detail

getNamespaceURI

public String getNamespaceURI()

Retrieves the Namespace URI of this QName.

Returns:
the Namespace URI of this QName.
Since:
BlackBerry API 4.3.0

getLocalPart

public String getLocalPart()

Retrieves the local name of this QName.

Returns:
the local name of this QName.
Since:
BlackBerry API 4.3.0

getPrefix

public String getPrefix()

Retrieves the prefix of this QName.

Returns:
the prefix of this QName.
Since:
BlackBerry API 4.3.0

equals

public boolean equals(Object anObject)

Equality testing for QNames. Two QNames are defined to be equal to each other iff their Namespace URIs and their local names are the same.

Note: Their prefixes might be different.

Overrides:
equals in class Object
Parameters:
anObject - the Object for equality testing.
Returns:
true if anObject is equal to this QName; false otherwise.
See Also:
Boolean.hashCode(), Hashtable
Since:
BlackBerry API 4.3.0

hashCode

public int hashCode()

Generates the hash code for this QName.

Overrides:
hashCode in class Object
Returns:
the hash code for this QName.
See Also:
Object.equals(java.lang.Object), Hashtable
Since:
BlackBerry API 4.3.0

toString

public String toString()

Returns a String representation of this QName.

If the Namespace URI of this QName is the empty string, return the localName; otherwise, return a string of the form
    "{" + namespaceURI + "}" + localName.

Overrides:
toString in class Object
Returns:
a String representation of this QName.
Since:
BlackBerry API 4.3.0

valueOf

public static QName valueOf(String aString)

Given the string representation of a QName, constructs the QName with the prefix being set to the empty string.

Note:This operation is the inverse of QName.toString.

Parameters:
aString - the string representation of a QName.
Returns:
the QName constructed from aString
Throws:
IllegalArgumentException - if aString is not of the form returned by QName.toString.
See Also:
QName.toString()
Since:
BlackBerry API 4.3.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal