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:
  • Method Details

    • getName

      String getName()
      Returns the node name. 返回节点名称。
      Returns:
      the node name | 节点名称
    • 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

      String getText()
      Returns the text content. 返回文本内容。
      Returns:
      the text content | 文本内容
    • 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

      Node getNode()
      Returns the underlying DOM Node. 返回底层的 DOM 节点。
      Returns:
      the DOM node | DOM 节点
    • toXml

      String toXml()
      Converts this node to XML string. 将此节点转换为 XML 字符串。
      Returns:
      the XML string | XML 字符串
    • toXml

      String toXml(int indent)
      Converts this node to XML string with indentation. 将此节点转换为带缩进的 XML 字符串。
      Parameters:
      indent - the number of spaces for indentation | 缩进空格数
      Returns:
      the formatted XML string | 格式化的 XML 字符串
    • toMap

      Map<String,Object> toMap()
      Converts this node to a Map. 将此节点转换为 Map。
      Returns:
      the Map representation | Map 表示