[
Lists Home |
Date Index |
Thread Index
]
- From: "Clark C. Evans" <clark.evans@manhattanproject.com>
- To: Paul Miller <stele@fxtech.com>
- Date: Sun, 19 Dec 1999 05:42:45 -0500 (EST)
Does this code fragment help out? It is far from
perfect, however, the "pull" based code would call
getNextEvent() to return the next XML event...
XML_Parser parser;
FILE *fileptr;
struct Event { .... };
Stack<Event> stack;
void initialize(const char *filename) {
fileptr = fopen(filename, ...);
parser = XML_ParserCreate(..);
}
Event getNextEvent() {
if(NULL==parser)
throw Error("Invalid Function Sequence");
while(stack.isEmpty())
{
const int BUFSIZ = 4096;
char buff[BUFSIZ];
// fill buffer with next chunk
// of the file being read, make sure
// that at least one new element is
// put on the stack..
int len = fread(fileptr, ... );
XML_Parse(parser, buff, len, (len!=BUFSIZ));
if(len!=BUFSIZ)
break;
}
if(!stack.isEmpty())
return stack.pop();
// if you get this far, we are at EOF
fclose(fileptr);
XML_ParserFree(parser);
parser = NULL;
fileptr = NULL;
return NULL;
}
void StartElementHandler(void *userData,
const XML_Char *name,
const XML_Char **atts)
{
// code to put event on the stack
newelements++;
}
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)
|