Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] qi xml parser
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-07-07 00:13:35


On 1/07/2014 08:14, Michael Powell wrote:
> So far so good, makes sense parsing names and so forth. However, how
> do you handle element content? Which could either be a string, or zero
> or more other elements (basically of the same rule as the enclosing
> element rule).
>
> It would seem you need a terminus, the empty element tag. In such a
> way that populates the parent (initial) element, and its children (of
> the same element kind).

Usually this sort of thing is resolved by using nodes -- a node is the
basic base type of everything, and the entire tree can be treated as a
homogenous tree of nodes. But specific derived types of nodes vary in
behaviour, eg. an element node represents a tag, an attribute node
modifies its parent element, a text node can only contain basic text (no
sub-nodes), a whitespace node can only contain whitespace (and can be
discarded or reinserted unless it's a significant-whitespace node), etc.

You could either use actual inheritance or you could make "node" a
variant type over the various "subtypes". Which one makes more sense
may depend on how much implementation they end up wanting to have in common.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net