getPrefix (NamespaceContext - JavaScript)
Gets the first prefix for a URI.
Defined in
NamespaceContextSyntax
getPrefix(name:string) : string
| Parameters | Description |
|---|---|
name |
A URI in the namespace context. |
| Return value | Description |
|---|---|
string |
The first matching prefix, or null if the URI does not exist. |
Usage
Multiple prefixes can have the same URI. See getPrefixes to get multiple prefixes.Examples
This button creates a document using a namespace to set a string value. The prefix for the XPath for the string value is obtained from the namespace context. The namespace context (sessionScope.ns), input value (requestScope.s),
and display area (requestScope.msg) are global variables
defined elsewhere on the page.var doc = database.createNewDocument();
var dom = doc.getDOM();
if(sessionScope.ns != null) {
dom.setSelectionNamespaces(sessionScope.ns);
var p = sessionScope.ns.getPrefix("http://mynamespace0.com");
if(p != null) {
dom.setStringValue("/" + p + ":schema1/" + p + ":element0", requestScope.s);
doc.save()
} else {
requestScope.msg = "No namespace for http://mynamespace0.com";
}
} else {
requestScope.msg = "No namespaces";
}