implement an xml parser using state pattern

S

stephen.nil

http://code.google.com/p/spxml/
http://spxml.googlecode.com/files/spxml-0.1.src.tar.gz
Simple Plain Xml Parser (spxml) is a simple and plain stream-oriented
XML parser that supports pull-model and DOM-model XML parsing. As the
user passes it chunks of an XML document, it identifies elements,
character data, or other entities and return the appropriate event.
Chunks can range from one byte to the whole XML document and can safely
be read from pipes. Resulting DOM trees can be read, modified, and
saved.

Using state pattern make it simple to implement the xml parser.

State pattern has three participants:
* Context ( SP_XmlPullParser )
o defines the interface of interest to clients
o maintains an instance of a ConcreteState subclass that
defines the current state.
* State ( SP_XmlReader )
o defines an interface for encapsulating the behavior
associated with a particular state of the Context.
* Concrete State ( SP_XmlStartTagReader, SP_XmlEndTagReader, etc )
o each subclass implements a behavior associated with a state
of Context
 
S

stephen.nil

Test with xmlbench<http://xmlbench.sourceforge.net/> framework.

Test result:

expat-2.0.0 + Sablot-1.0.3

--->Running <expat-sablotron-dom> benchmarks:
-> xmlgen 4 KB
Initialisation time 0.106 + 0.613(6.48%) ms, Parsing Time 1.620(2.45%)
ms
-> xmlgen 256 KB
Initialisation time 0.137 + 1.121(114.60%) ms, Parsing Time
126.102(1.02%) ms

spxml

--->Running <spxml-dom> benchmarks:
-> xmlgen 4 KB
Initialisation time 0.002 + 0.388(16.89%) ms, Parsing Time 1.601(4.09%)
ms
-> xmlgen 256 KB
Initialisation time 0.002 + 5.474(30.01%) ms, Parsing Time
164.281(1.00%) ms
 
J

Joseph Kesselman

It is trivial to write a trivial-subset parser of XML that performs
well. It is much, much harder to write a complete implementation that
performs well. Classic 90/10 problem.
 
G

geoff

Exactly, I played with the xml spec a little and some of the BNF makes it
LR(2). I tried rewriting some of those statements but it is very difficult
work.

-g
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top