Class NamespaceUtil
java.lang.Object
cloud.opencode.base.xml.namespace.NamespaceUtil
Namespace Utility - Utilities for XML namespace operations
命名空间工具 - XML 命名空间操作的工具类
This class provides utility methods for working with XML namespaces.
此类提供处理 XML 命名空间的工具方法。
Features | 主要功能:
- Utility methods for XML namespace operations - XML 命名空间操作的工具方法
- Namespace extraction from DOM documents - 从 DOM 文档提取命名空间
- Common namespace URI constants - 常用命名空间 URI 常量
Usage Examples | 使用示例:
// Extract namespaces from document
Map<String, String> namespaces = NamespaceUtil.extractNamespaces(document);
// Get namespace URI for prefix
String uri = NamespaceUtil.getNamespaceURI(element, "soap");
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具)
- Null-safe: No (throws on null document) - 空值安全: 否(null 文档抛异常)
Performance | 性能特性:
- Time complexity: O(d×a) for extractNamespaces where d=ancestor depth and a=attributes per element; O(n) for string operations (getLocalPart, getPrefix, createQName) where n=string length; O(1) for namespace checks - 时间复杂度: extractNamespaces 为 O(d×a),d 为祖先深度,a 为每个元素的属性数;字符串操作 O(n),n 为字符串长度;命名空间检查为 O(1)
- Space complexity: O(d) for namespace map entries from ancestor chain - 空间复杂度: 祖先链的命名空间 map 条目为 O(d)
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenNamespaceContextcreateContext(XmlDocument document) Creates a namespace context from a document.static OpenNamespaceContextcreateContext(XmlElement element) Creates a namespace context from an element.static OpenNamespaceContextcreateContextFromMap(Map<String, String> namespaces) Creates a namespace context from a map.static StringcreateQName(String prefix, String localPart) Creates a qualified name from prefix and local part.static voiddeclareDefaultNamespace(XmlElement element, String namespaceUri) Adds a default namespace declaration to an element.static voiddeclareNamespace(XmlElement element, String prefix, String namespaceUri) Adds a namespace declaration to an element.extractNamespaces(XmlDocument document) Extracts all namespace declarations from a document.extractNamespaces(XmlElement element) Extracts all namespace declarations from an element and its ancestors.extractNamespaces(Element element) Extracts namespace declarations from a DOM element and its ancestors.static StringgetLocalPart(String qName) Gets the local part of a qualified name.static StringgetNamespacePrefix(XmlElement element) Gets the namespace prefix of an element.static StringgetNamespaceUri(XmlElement element) Gets the namespace URI of an element.static StringGets the prefix of a qualified name.static booleanhasNoNamespace(XmlElement element) Checks if an element has no namespace.static booleanisInNamespace(XmlElement element, String namespaceUri) Checks if an element is in a specific namespace.static booleanisQualifiedName(String name) Checks if a name is a qualified name (has a prefix).static voidremoveNamespaceDeclaration(XmlElement element, String prefix) Removes a namespace declaration from an element.static OpenNamespaceContextCreates a namespace context for SOAP 1.2.static OpenNamespaceContextCreates a namespace context for SOAP 1.1.static OpenNamespaceContextCreates a namespace context for XML Schema.
-
Field Details
-
XMLNS_URI
-
XML_URI
- See Also:
-
XSI_URI
- See Also:
-
XSD_URI
- See Also:
-
SOAP_ENV_URI
- See Also:
-
SOAP12_ENV_URI
- See Also:
-
-
Method Details
-
extractNamespaces
Extracts all namespace declarations from a document. 从文档中提取所有命名空间声明。- Parameters:
document- the document | 文档- Returns:
- map of prefix to namespace URI | 前缀到命名空间 URI 的映射
-
extractNamespaces
Extracts all namespace declarations from an element and its ancestors. 从元素及其祖先中提取所有命名空间声明。- Parameters:
element- the element | 元素- Returns:
- map of prefix to namespace URI | 前缀到命名空间 URI 的映射
-
extractNamespaces
-
createContext
Creates a namespace context from a document. 从文档创建命名空间上下文。- Parameters:
document- the document | 文档- Returns:
- a namespace context | 命名空间上下文
-
createContext
Creates a namespace context from an element. 从元素创建命名空间上下文。- Parameters:
element- the element | 元素- Returns:
- a namespace context | 命名空间上下文
-
createContextFromMap
Creates a namespace context from a map. 从映射创建命名空间上下文。- Parameters:
namespaces- the namespace map | 命名空间映射- Returns:
- a namespace context | 命名空间上下文
-
getLocalPart
-
getPrefix
-
createQName
-
isQualifiedName
Checks if a name is a qualified name (has a prefix). 检查名称是否是限定名(具有前缀)。- Parameters:
name- the name | 名称- Returns:
- true if qualified | 如果是限定名则返回 true
-
declareNamespace
Adds a namespace declaration to an element. 向元素添加命名空间声明。- Parameters:
element- the element | 元素prefix- the prefix | 前缀namespaceUri- the namespace URI | 命名空间 URI
-
declareDefaultNamespace
Adds a default namespace declaration to an element. 向元素添加默认命名空间声明。- Parameters:
element- the element | 元素namespaceUri- the namespace URI | 命名空间 URI
-
removeNamespaceDeclaration
Removes a namespace declaration from an element. 从元素中移除命名空间声明。- Parameters:
element- the element | 元素prefix- the prefix to remove | 要移除的前缀
-
getNamespaceUri
Gets the namespace URI of an element. 获取元素的命名空间 URI。- Parameters:
element- the element | 元素- Returns:
- the namespace URI, or null | 命名空间 URI,或 null
-
getNamespacePrefix
Gets the namespace prefix of an element. 获取元素的命名空间前缀。- Parameters:
element- the element | 元素- Returns:
- the prefix, or null | 前缀,或 null
-
isInNamespace
Checks if an element is in a specific namespace. 检查元素是否在特定命名空间中。- Parameters:
element- the element | 元素namespaceUri- the namespace URI | 命名空间 URI- Returns:
- true if in the namespace | 如果在命名空间中则返回 true
-
hasNoNamespace
Checks if an element has no namespace. 检查元素是否没有命名空间。- Parameters:
element- the element | 元素- Returns:
- true if no namespace | 如果没有命名空间则返回 true
-
soapContext
Creates a namespace context for SOAP 1.1. 创建 SOAP 1.1 的命名空间上下文。- Returns:
- a namespace context | 命名空间上下文
-
soap12Context
Creates a namespace context for SOAP 1.2. 创建 SOAP 1.2 的命名空间上下文。- Returns:
- a namespace context | 命名空间上下文
-
xsdContext
Creates a namespace context for XML Schema. 创建 XML Schema 的命名空间上下文。- Returns:
- a namespace context | 命名空间上下文
-