Class OpenNamespaceContext
java.lang.Object
cloud.opencode.base.xml.namespace.OpenNamespaceContext
- All Implemented Interfaces:
NamespaceContext
Open Namespace Context - NamespaceContext implementation for XPath
开放命名空间上下文 - 用于 XPath 的 NamespaceContext 实现
This class provides a simple implementation of NamespaceContext for use with XPath.
此类提供用于 XPath 的 NamespaceContext 简单实现。
Usage Examples | 使用示例:
// Create namespace context
OpenNamespaceContext ctx = OpenNamespaceContext.create()
.bind("soap", "http://schemas.xmlsoap.org/soap/envelope/")
.bind("xsd", "http://www.w3.org/2001/XMLSchema");
// Use with XPath
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(ctx);
String result = xpath.evaluate("//soap:Body", document);
Features | 主要功能:
- NamespaceContext implementation for XPath evaluation - 用于 XPath 求值的 NamespaceContext 实现
- Fluent API for prefix-URI binding - 用于前缀-URI 绑定的流式 API
- Pre-bound standard XML namespaces - 预绑定的标准 XML 命名空间
Security | 安全性:
- Thread-safe: No (mutable bindings) - 线程安全: 否(可变绑定)
- Null-safe: No (throws on null prefix/URI) - 空值安全: 否(null 前缀/URI 抛异常)
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionBinds a prefix to a namespace URI.static OpenNamespaceContextcreate()Creates a new namespace context.Gets all bindings.getNamespaceURI(String prefix) Gets all bound prefixes.getPrefixes(String namespaceUri) booleanChecks if a prefix is bound.static OpenNamespaceContextCreates a namespace context with a single binding.static OpenNamespaceContextCreates a namespace context from a map.setDefaultNamespace(String namespaceUri) Sets the default namespace URI.toString()Removes a prefix binding.
-
Method Details
-
create
Creates a new namespace context. 创建新的命名空间上下文。- Returns:
- a new context | 新上下文
-
of
Creates a namespace context from a map. 从映射创建命名空间上下文。- Parameters:
prefixToUri- the prefix to URI map | 前缀到 URI 映射- Returns:
- a new context | 新上下文
-
of
Creates a namespace context with a single binding. 创建具有单个绑定的命名空间上下文。- Parameters:
prefix- the prefix | 前缀namespaceUri- the namespace URI | 命名空间 URI- Returns:
- a new context | 新上下文
-
bind
Binds a prefix to a namespace URI. 将前缀绑定到命名空间 URI。- Parameters:
prefix- the prefix | 前缀namespaceUri- the namespace URI | 命名空间 URI- Returns:
- this context for chaining | 此上下文以便链式调用
-
setDefaultNamespace
Sets the default namespace URI. 设置默认命名空间 URI。- Parameters:
namespaceUri- the namespace URI | 命名空间 URI- Returns:
- this context for chaining | 此上下文以便链式调用
-
unbind
Removes a prefix binding. 移除前缀绑定。- Parameters:
prefix- the prefix to remove | 要移除的前缀- Returns:
- this context for chaining | 此上下文以便链式调用
-
isBound
Checks if a prefix is bound. 检查前缀是否已绑定。- Parameters:
prefix- the prefix | 前缀- Returns:
- true if bound | 如果已绑定则返回 true
-
getPrefixes
-
getBindings
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceNamespaceContext
-
getPrefix
- Specified by:
getPrefixin interfaceNamespaceContext
-
getPrefixes
- Specified by:
getPrefixesin interfaceNamespaceContext
-
toString
-