473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

implement an xml parser using state pattern

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 '07 #1
3 2163
Test with xmlbench<http://xmlbench.sourceforge.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

Jan 19 '07 #2
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.
Jan 19 '07 #3
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
Jan 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3173
by: lawrence | last post by:
To call I would do something like: $headline = McSelectJustOneField::callDatastore("cbHeadline"); Is this the correct use of the static keyword, to implement a Singleton design?
3
1930
by: cr88192 | last post by:
for various reasons, I added an imo ugly hack to my xml parser. basically, I wanted the ability to have binary payload within the xml parse trees. this was partly because I came up with a binary...
4
3077
by: billcoumbe | last post by:
any recommendations? I'm looking for something that will just run from the unix command line to validate large (20-50Mb) XML files against an XML DTD. Ideally something that is actively...
14
3118
by: WUV999U | last post by:
Hi I am fairly familiar in C but not much. I want to know how I can write a html parser in C that only parses for the image file in the html file and display or print all the images found in...
4
2799
by: siddharthkhare | last post by:
Hi All, I need to parse certain text from a paragraph (like 20 lines). I know the exact tags that I am looking for. my approach is to define a xml (config) file that defines what tag I am...
0
1450
by: stephen.nil | last post by:
http://code.google.com/p/spxml/ spxml is a xml parser, supports PULL-model and DOM-model xml parsing. Using state pattern make it simple to implement the xml parser. State pattern has three...
5
4019
by: gordon.is.a.moron | last post by:
Hello, I'm implementing a State Pattern in C++, based on the example in the GoF book. However the example they give only shows a single transition to another state. In my program I have a choice...
1
1735
by: sunil | last post by:
Hello, I am working on a problem where I will have a boolean expression with upto four variables: A,B,C,D and connected by basic operator &&,||and may be XOR and NOT in future AND has higher...
0
1336
by: arvindkgs | last post by:
Iam using c lexer that is flex generated and a c++ parser that is bison generated. i have modified the parser to acccept only string input. I am calling the parser function yyparse in a loop and...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.