Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2003-06-12 00:33:43


> * event driven xml file parsing (sax)

I did not really used DOM to much. I may have some comments on SAX though.
Perfunctory look on your interfaces left me wondering: who does it differ
from xerces? Still xmlChar type, tons of virtual functions. We are in modern
C++ world. No need to promote such a Javish solution.

  Here is my vision on the problem, couple ideas on XML parser design:
1. No xmlChar type -> template parameter

namespace xml {
template<typename Ch, typename Tr>
class parser {...};
}

2. No hardcoded virtual functions. In some refinements it still may come to
use virtual functions here and there. One way to achieve this is to supply
implementation as template parameter:

namespace xml {
template<typename HandlerImpl>
class parser : public HandlerImpl {...};
}

3. Most probably above may not be good enough. For better reusability let
then use multiple template parameters for different types of handlers:

namespace xml {
template<typename DocumentHandler, typename ErrorHandler, typename
DTDHandler, ...>
class parser : public foo( DocumentHandler, ErrorHandler, DTDHandler, ... )
{...};
}

meta function foo should deduce the correct type to inherit from. We may
want to take into an account the fact that if the same type is used as both
document and error handler, we don't want to inherit twice.
 Also above interface definitely asks for named template parameters.

4. There maybe several "flavors" of document handlers. One simple: as usual
concrete handler needs to expose methods like on_start_element and accept
the name plus attributes. As an alternative we may consider document
handlers supporting "named callbacks" (in a form of boost::function<...>)
registration. IOW such handler would call a callback when element with
desired name encountered. There are other alternatives.

This way I believe we could create fastest and convenient parser.

I am sure that there also could be Spirit-based or Spirit-like solution.
Check with the Spirit guys.

Regards,

Gennadiy.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk