[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: SAX and stuff ...

  • From: Michael Brennan <Michael_Brennan@A...>
  • To: "'Xml-Dev (E-mail)'" <xml-dev@l...>
  • Date: Tue, 25 Jul 2000 12:35:42 -0700

sax elementhandler
I've used essentially the same approach, and it has worked well. However,
more recently I switched to a different approach. I felt that this approach
somewhat constrains extensibility. Each node that accepts children must be
responsible for creating every possible type of child.

My more recent approach is to have an "addChild" method on what you are
calling the ParserListener (which I called "ElementHandler" in my
implementation). Then, I use a simple Hashtable (loaded from a Java
Properties file) to map element names to a class that is loaded via
reflection (just as Stefan Haustein noted in another post). The BaseHandler
that is maintaining the stack of current ElementHandlers invokes "addChild"
on the parent ElementHandler after instantiating a new ElementHandler.

This child, of course, needs to derive from a type that the parent knows how
to deal with, but at least it can exploit polymorphism, here, and the parent
need not be responsible for knowing every possible specialization that can
be instantiated.

> From: jar@m... [mailto:jar@m...]On
> [...]
>   I use DTDs; I think you should, too.  But, with that in
> mind, here is
> how I do it (all examples in C++):
>
>   o Create an ObjectFactory (in the GoF object sense) that can make
> objects based on string names.
>
>   o Make a ParserListener interface that has stuff like this in it:
> <interface>
> public:
>     // start creating a child object.
>   virtual ParserListener* createChildObject( const string
> object ) = 0;
>
>   // complete a child object.
>   virtual ParserListener* completeChildObject( const string object ) =
> 0;
>
>   // get the value of an object attribute.
>   virtual const string getAttribute( const string newKey ) = 0;
>
>   // set attribute "key" to value "value" for this node.
>   virtual void setAttribute( const string key, const string
> value ) = 0;
>
> protected:
>   // clean up my children after parsetime.
>   virtual void arrangeChildren() = 0;
> </interface>
>
>   o Extend the BaseHandler into a class that has a private member that
> is a ParserListener, and implement a stack of previous ParserListener
> objects.
>
>   o StartElement() pushes the current ParserListener onto the
> stack and
> sets it to the return of a call to the current ParserListener's
> createChildObject() method.  The createChildObject() method
> makes a call
> to the aforementioned ObjectFactory and returns the new object (which,
> itself, is also a ParserListener).
>
>   o EndElement() calls the ParserListener's
> completeChildObject() method
> and pops the old ParserListener off of the stack (reassigning the
> current ParserListener to it).  The completeChildObject() calls calls
> the object's arrangeChildren() method to do any final cleanup and
> reorganization of the tree that was built from the parse.
> [...]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.