On Tue, 27 Apr 2004, Adam Heinz wrote:
>
> It sounds like you are doing SAX, yes?
>
> I use a simple list (stack) to maintain state.  I tokenize my element
> and attribute names into integers.  In some cases, I use a hash table to
> index function pointers by token.  In other cases, I just switch (ugh)
> on the token; not much better than if/elsif.

I do pretty much the same thing.  I do a switch on state and then compare
the label against a list of valid labels.  If the label isn't
recognized then I ignore that entire subtree.  So it's a state machine
with the schema structure pretty much hardcoded into the app, but it's
very readable IMO.  At a lower level I have a pluggable event handler
that I pass the constructed objects off to, so I only ever touch the
parsing code itself when the schema is altered (ie. basically never).  I
strongly resist the idea of complex XML schemas so this works quite well
for me in a fairly small amount of code.  If I were forced to deal with a
much larger schema I'd probably make the whole process more generic and
pluggable, but along the same lines.


Sean

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to