OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: nestable C/C++ XML parser?

[ Lists Home | Date Index | Thread Index ]
  • From: Paul Miller <stele@fxtech.com>
  • Date: Tue, 07 Dec 1999 15:46:26 -0500

> Ignore my response on xml-dev: I incorrectly guessed what you wanted to
> do.  Let me try again.  This time it looks like what you want to do is
> process Foo and its contents with a different set of handlers than the
> rest of the document.  If that's the case, have your "standard"
> StartElement handler set new handlers when it encounters a Foo and have
> the new EndElement handler set the handlers back to the "standard" ones
> when it encounters the end of a Foo.  If necessary, maintain a stack of
> pointers to handlers.

This is a good idea on the surface, and where I started down in my
implementation when I hit a snag. This provides too much housekeeping,
and too many functions if you want to do something special when the
element is finished (such as add the just-parsed object to a list). 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);
}

Object::Parse(XML_Element &element)
{
	XML_ElementHandler handlers[] = {
		... object-specific element handlers ...
	};
	// parse just the object subtree to the </Object> token
	element.Parse(handlers, this);
}

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@fxtech.com

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@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@ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS