NamespaceContext (JavaScript)

Represents a namespace context.

Defined in

DOM (JavaScript)

Usage

To create and manipulate a namespace context, see NamespaceContextImpl (JavaScript) which inherits from NamespaceContext.

A namespace context is a list of namespaces. Each namespace consists of a prefix and an associated URI. A namespace context can be specified before or in a method that takes an XPath to resolve prefixes in the XPath.

Search the Web using the keyword "namespace" for information on namespaces.

Examples

The following code creates a namespace context with two namespaces. The prefixes are ns0 and ns1, and the URIs are http://mynamespace0.com and http://mynamespace1.com.
var ns = new NamespaceContextImpl();
ns.addNamespace("ns0", "http://mynamespace0.com");
ns.addNamespace("ns1", "http://mynamespace1.com");
This follow-on code gets a document from the database using one of the namespaces in the XPath specification.
var dc = database.getAllDocuments();
if(dc.getDocumentCount() > 0) {
	if(requestScope.i != null && requestScope.i >= 0 && requestScope.i < dc.getDocumentCount()) {
		var ar = dc.getDocumentArray(requestScope.i + 1);
		var doc = ar[requestScope.i];
		var dom = doc.getDOM();
		requestScope.y = dom.getStringValue("/ns0:schema1/ns0:element0", ns);
	} else {
		requestScope.msg = "No such document";
	}
} else {
	requestScope.msg = "No documents in database";
}