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

被折叠的 条评论
为什么被折叠?



