implement an xml parser using state pattern

Discussion in 'XML' started by stephen.nil@gmail.com, Jan 19, 2007.

  1. Guest

    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
    , Jan 19, 2007
    #1
    1. Advertising

  2. Guest

    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
    , Jan 19, 2007
    #2
    1. Advertising

  3. 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.
    Joseph Kesselman, Jan 19, 2007
    #3
  4. geoff Guest

    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
    geoff, Jan 19, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    356
  2. Replies:
    0
    Views:
    422
  3. arne
    Replies:
    0
    Views:
    351
  4. Sean
    Replies:
    3
    Views:
    267
    robic0
    Oct 3, 2006
  5. Sean
    Replies:
    0
    Views:
    365
Loading...

Share This Page