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.