XML parser

1, SAX (Simple API for XML)
2, a SAX Parser functions implemented as a stream parser, with an event-driven API.The user defines a number of callback methods that will be called when events occur during parsing
3,Example

Given the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
<RootElement param="value">
    <FirstElement>
        Some Text
    </FirstElement>
    <SecondElement param2="something">
        Pre-Text <Inline>Inlined text</Inline> Post-text.
    </SecondElement>
</RootElement>

This XML document, when passed through a SAX parser, will generate a sequence of events like the following:

  • XML Processing Instruction, named xml, with attributes version equal to "1.0" and encoding equal to "UTF-8"
  • XML Element start, named RootElement, with an attribute param equal to "value"
  • XML Element start, named FirstElement
  • XML Text node, with data equal to "Some Text" (note: text processing, with regard to spaces, can be changed)
  • XML Element end, named FirstElement
  • XML Element start, named SecondElement, with an attribute param2 equal to "something"
  • XML Text node, with data equal to "Pre-Text"
  • XML Element start, named Inline
  • XML Text node, with data equal to "Inlined text"
  • XML Element end, named Inline
  • XML Text node, with data equal to "Post-text."
  • XML Element end, named SecondElement
  • XML Element end, named RootElement

In fact, this may vary: the SAX specification deliberately states that a given section of text may be reported as multiple sequential text events. Thus in the example above, a SAX parser may generate a different series of events, part of which might include:

  • XML Element start, named FirstElement
  • XML Text node, with data equal to "Some"
  • XML Text node, with data equal to "Text"
  • XML Element end, named FirstElement

4,Benefits
The quantity of memory that a SAX parser must use in order to function is typically much smaller than that of a DOM parser

5, Drawbacks
XML Validation require access to the document in full

6. XML Parser and APIs supporting SAX
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值