implement an xml parser using state pattern

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stephen.nil@gmail.com

    #1

    implement an xml parser using state pattern



    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_XmlPullParse r )
    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_XmlStartTagR eader, SP_XmlEndTagRea der, etc )
    o each subclass implements a behavior associated with a state
    of Context

  • stephen.nil@gmail.com

    #2
    Re: implement an xml parser using state pattern

    Test with xmlbench<http://xmlbench.source forge.net/framework.

    Test result:

    expat-2.0.0 + Sablot-1.0.3

    --->Running <expat-sablotron-dombenchmarks:
    -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-dombenchmarks:
    -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

    Comment

    • Joseph Kesselman

      #3
      Re: implement an xml parser using state pattern

      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.

      Comment

      • geoff

        #4
        Re: implement an xml parser using state pattern

        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


        Comment

        Working...