getPrefixes (NamespaceContext - JavaScript)
Gets multiple prefixes.
Defined in
NamespaceContextSyntax
getPrefixes() : java.util.Iterator
getPrefixes(name:string) : java.util.Iterator
Parameters | Description |
---|---|
name |
A URI in the namespace context. Omission of this parameter means all prefixes. Inclusion of this parameter means all prefixes with this URI. |
Return value | Description |
---|---|
java.util.Iterator |
The matching prefixes, or null if the URI does not exist. |
Usage
Multiple prefixes can have the same URI in a namespace context.The
java.util.Iterator
class
has the following methods:Method | Description |
---|---|
public boolean hasNext() |
Returns true if the iteration has more elements. |
public Object next() |
Returns the next element in the iteration. |
public void remove() |
Removes the last element returned by the iterator. |
Examples
(1) This button displays all prefixes and corresponding URIs in a namespace context. The namespace context (sessionScope.ns
) and display areas (requestScope.y
and requestScope.msg
)
are global variables defined elsewhere on the page.if(sessionScope.ns != null) {
requestScope.y = "Namespaces";
var p = sessionScope.ns.getPrefixes();
while(p.hasNext()) {
var np = p.next();
requestScope.y = requestScope.y + "\n\t" +
np + " = " + ns.getNamespaceURI(np);
}
} else {
requestScope.msg = "No namespaces";
}
(2) This button displays all prefixes whose URI is
http://mynamespace.com
.if(sessionScope.ns != null) {
requestScope.y = "Namespaces";
var p = sessionScope.ns.getPrefixes("http://mynamespace.com");
while(p.hasNext()) {
var np = p.next();
requestScope.y = requestScope.y + "\n\t" +
np + " = " + ns.getNamespaceURI(np);
}
} else {
requestScope.msg = "No namespaces";
}