Interface SaxHandler

All Known Implementing Classes:
SimpleSaxHandler

public interface SaxHandler
SAX Handler Interface - Handles SAX parsing events SAX 处理器接口 - 处理 SAX 解析事件

This interface defines callbacks for SAX parsing events with a simplified API.

此接口使用简化 API 定义 SAX 解析事件的回调。

Features | 主要功能:

  • Simplified SAX event callback interface - 简化的 SAX 事件回调接口
  • Default no-op implementations for all methods - 所有方法的默认无操作实现
  • Element start/end and text content callbacks - 元素开始/结束和文本内容回调

Usage Examples | 使用示例:

// Implement custom handler
SaxHandler handler = new SaxHandler() {
    @Override
    public void startElement(String name, Map<String, String> attrs) {
        System.out.println("Start: " + name);
    }
    @Override
    public void text(String text) {
        System.out.println("Text: " + text);
    }
};

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: Yes (default no-op methods) - 空值安全: 是(默认无操作方法)
Since:
JDK 25, opencode-base-xml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • startDocument

      default void startDocument()
      Called when document parsing starts. 当文档解析开始时调用。
    • endDocument

      default void endDocument()
      Called when document parsing ends. 当文档解析结束时调用。
    • startElement

      default void startElement(String uri, String localName, String qName, Map<String,String> attributes)
      Called when an element starts. 当元素开始时调用。
      Parameters:
      uri - the namespace URI | 命名空间 URI
      localName - the local name | 本地名称
      qName - the qualified name | 限定名称
      attributes - the element attributes | 元素属性
    • endElement

      default void endElement(String uri, String localName, String qName)
      Called when an element ends. 当元素结束时调用。
      Parameters:
      uri - the namespace URI | 命名空间 URI
      localName - the local name | 本地名称
      qName - the qualified name | 限定名称
    • characters

      default void characters(String content)
      Called for character content. 为字符内容调用。
      Parameters:
      content - the character content | 字符内容
    • processingInstruction

      default void processingInstruction(String target, String data)
      Called for processing instructions. 为处理指令调用。
      Parameters:
      target - the target | 目标
      data - the data | 数据
    • error

      default void error(SaxParseException e)
      Called when a parsing error occurs. 当发生解析错误时调用。
      Parameters:
      e - the parse exception | 解析异常
    • warning

      default void warning(SaxParseException e)
      Called for parsing warnings. 为解析警告调用。
      Parameters:
      e - the parse exception | 解析异常