nestable C/C++ XML parser?
Thomas B. Passin
tpassin at idsonline.com
Wed Dec 8 13:47:34 GMT 1999
----- Original Message -----
From: Paul Miller <stele at fxtech.com>
> ...It [...] would be nicer to be able treat parsing of an element as an
atomic
> operation, so you can write code like this:
>
> Document::ParseDocument(XML_Input &in)
> {
> XML_ElementHandler handlers[] = {
> { "Object", ParseObject }
> { NULL }
> };
> in.Parse(handlers, this);
> }
>
> Docuement::ParseObject(XML_Element &element, void *userData)
> {
> Document *doc = (Document *)userData;
> Object *obj = new Object;
> obj->Parse(element);
> doc->AddObject(obj);
> }
>
...
> You see in ParseObject() that I can do everything I need to create a new
> object, parse it, and do something with it after I've parsed it. I can
> only do this if the parser lets me parse just a subtree and then stop
> (ie. it returns control back to me when it finds the </Object> token).
>
> --
> Paul Miller - stele at fxtech.com
You can see the difficulty - if you send a fragment to a parser it's not a
valid xml document (so the parser can't work with it). You could start
building a subtree when you get to the point of interest, using DOM calls,
but you keep saying you don't want to deal with DOM.
Where you are being unclear is when you say "parse just a subtree". It is
unclear whether you think you need to get (or build) an actual tree
structure, or whether the expression is just a shorthand for indicating a
place in the document. It is also unclear when you say that, because how do
you know that you are at the right starting place in the document? I assume
that you have been parsing from the start of the document to get to the
point of interest. Then you say you want to start parsing at that point.
See why it's confusing?
If you just want to know the names of the elements in the fragment, just
keep a state variable. I know you said it's too much machinery, but maybe
there is a way it wouldn't be.
Alternatively, there are other tree builders that are simpler than DOM.
Look at Sean McGrath's xml tree code in (I think) "XML By Example) for one
example. Of course it depends on the complexity of what you are doing.
All in all, I still think that a preprocessing pass to extract the fragments
you want to look at, as I mentioned in my previous post, is the way to go.
Tom Passin
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list