Handling Lexical Events

本文介绍了如何使用SAX解析器中的LexicalHandler来处理文档中的词汇信息,包括注释、CDATA段、实体及DTD等元素。通过实现特定接口的方法,应用程序可以接收这些信息并进行相应的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How the LexicalHandler Works

To be informed when the SAX parser sees lexical information, you configure the XmlReader that underlies the parser with a LexicalHandler. The LexicalHandler interface defines these event-handling methods:

comment(String comment)

Passes comments to the application

startCDATA(), endCDATA()

Tells when a CDATA section is starting and ending, which tells your application what kind of characters to expect the next time characters() is called

startEntity(String name), endEntity(String name)

Gives the name of a parsed entity

startDTD(String name, String publicId, String systemId), endDTD()

Tells when a DTD is being processed, and identifies it

下面是具体的函数体
public void comment(char[] ch, int start, int length)
throws SAXException
{
}

public void startCDATA()
throws SAXException
{
}

pubic void endCDATA()
throws SAXException
{
}

public void startEntity(String name)
throws SAXException
{
}

public void endEntity(String name)
throws SAXException
{
}

public void startDTD(
  String name, String publicId, String systemId)
throws SAXException
{
}

public void endDTD()
throws SAXException
{
}

 当startEntity(String name)和endEntity(String name)遇到DTD声明中部分,打印出来的内容,是StartEntity:[dtd],对于多个entity声明也只生成这一个打印。不显示具体的entity定义的变量的名字,只显示[dtd].

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值