Interface XmlNode
- All Known Implementing Classes:
XmlElement
public interface XmlNode
XML Node Interface - Base interface for XML nodes
XML 节点接口 - XML 节点的基础接口
This interface defines common operations for XML nodes including elements, attributes, text, and other node types.
此接口定义了 XML 节点的通用操作,包括元素、属性、文本和其他节点类型。
Features | 主要功能:
- Name and namespace access - 名称和命名空间访问
- Text content retrieval - 文本内容获取
- XML serialization with optional indentation - 带可选缩进的 XML 序列化
- Map conversion for data interchange - 用于数据交换的 Map 转换
Usage Examples | 使用示例:
XmlNode node = ...; // XmlElement implements XmlNode
String name = node.getName();
String text = node.getText();
String xml = node.toXml(4);
Map<String, Object> map = node.toMap();
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- Null-safe: Depends on implementation - 空值安全: 取决于实现
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionReturns the local name (without namespace prefix).getName()Returns the node name.Returns the namespace URI.getNode()Returns the underlying DOM Node.Returns the namespace prefix.getText()Returns the text content.Returns the text content trimmed.booleanhasText()Returns whether this node has any text content.toMap()Converts this node to a Map.toXml()Converts this node to XML string.toXml(int indent) Converts this node to XML string with indentation.
-
Method Details
-
getName
-
getLocalName
String getLocalName()Returns the local name (without namespace prefix). 返回本地名称(不含命名空间前缀)。- Returns:
- the local name | 本地名称
-
getNamespaceUri
String getNamespaceUri()Returns the namespace URI. 返回命名空间 URI。- Returns:
- the namespace URI, or null if not set | 命名空间 URI,如果未设置则返回 null
-
getPrefix
String getPrefix()Returns the namespace prefix. 返回命名空间前缀。- Returns:
- the prefix, or null if not set | 前缀,如果未设置则返回 null
-
getText
-
getTextTrim
String getTextTrim()Returns the text content trimmed. 返回去除空白的文本内容。- Returns:
- the trimmed text content | 去除空白的文本内容
-
hasText
boolean hasText()Returns whether this node has any text content. 返回此节点是否有任何文本内容。- Returns:
- true if has text content | 如果有文本内容则返回 true
-
getNode
-
toXml
-
toXml
Converts this node to XML string with indentation. 将此节点转换为带缩进的 XML 字符串。- Parameters:
indent- the number of spaces for indentation | 缩进空格数- Returns:
- the formatted XML string | 格式化的 XML 字符串
-
toMap
-