Simple API for XML

本文介绍了SAX(Simple API for XML)的工作原理及其特点,包括事件驱动模型、错误处理及与DOM、StAX的区别与联系。SAX适用于快速解析大型XML文件,尤其在资源受限的环境中表现出色。

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

SAX是Simple API for XML的简称。
什么是SAX?
Simple API for XML (SAX), an event-driven, serial-access mechanism for accessing XML documents.
SAX is an event-driven model (you provide the callback methods, and the parser invokes them as it reads the XML data), and that makes it harder to visualize. Finally, you can't "back up" to an earlier part of the document, or rearrange it, any more than you can back up a serial data stream or rearrange characters you have read from that stream.
很长的一段话,但是我以前使用过一个爬虫的程序,知道两种解析方法。一种是,你必须按照文章读取的顺序来解析文章。第二种,需要解析的文章已经被读到内存当中,并且用一种格式化的方式储存起来,你可以随即访问这个文章的某个元素,并且可以根据这个元素访问到跟这个元素有关系的元素。
 
另外SAX和DOM方式有一定的联系。
Same Error Handling: The same kinds of exceptions are generated by the SAX and DOM APIs, so the error handling code is virtually identical.
Handling Validation Errors: By default, the specifications require that validation errors (which you'll learn more about in this part of the tutorial) are ignored. If you want to throw an exception in the event of a validation error (and you probably do), then you need to understand how SAX error handling works.
Converting Existing Data: As you'll see in Chapter  6, there is a mechanism you can use to convert an existing data set to XML. However, taking advantage of that mechanism requires an understanding of the SAX model.
 
SAX,StAX,DOM之间的联系和区别
SAX:fast and efficient,not construct a internal structure.
StAX:a little different from SAX,use it to get the next node from any point of the code.
DOM:struct a more interactive view of document,easy to modify text or element in the xml document.
 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值