versadac  1
versadac - Scalable Recorder Firmware
zippedXmlReader.h
1 /*******************************************************************************
2 FILE : zippedXmlReader.h
3 VERSION : $Id$
4 AUTHOR : David Cozens
5 SYSTEM : LIN
6 DESCRIPTION : The zippedXmlReader code wraps the open source expat xml pareser
7  code with a simple table driven interface. The interface allows
8  for extractine element names, attributes and character data from
9  elements within the xml. As each element is encountered the table
10  is referenced to set handlers for expected sub elements and for
11  character data. Unexpeced elements (and their sub elements) are
12  silently skipped.
13 *******************************************************************************/
14 #ifdef __cplusplus
15 extern "C"
16 {
17 #endif /* __cplusplus */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #if __dcc__
21 #include <iolib.h>
22 #endif
23 #include <errno.h>
24 #include <string.h>
25 #include "expat.h"
26 #include "zlib.h"
27 
28 typedef void (*UnexpectedElementHandlerT) (void *userData, const XML_Char *elementName);
29 typedef void (*ParseErrorHandlerT) (void *userData, const char *z_errorString, int z_line);
30 
31  /* Data structure to describe all of the expected sub-elements of an element and what to do when parsing them. */
32  typedef struct SubElementDataS
33  {
34  char * name;
35  struct SubElementDataS * subElements;
36  XML_CharacterDataHandler charDataHandler;
37  XML_StartElementHandler startHandler;
38  XML_EndElementHandler endHandler;
40 
41  /* Data structure to hold a context we will unwind to on an end tag */
42  typedef struct HandlerSet
43  {
44  struct HandlerSet * parent;
45  SubElementDataT * subElements;
46  XML_EndElementHandler endHandler;
47  XML_CharacterDataHandler charDataHandler;
48  char *name;
49  } HandlerSetT;
50 
51 
52  /* User data to hold context whilst parsing */
53  typedef struct
54  {
55  XML_Parser parser;
56  int depth;
57  int endDepth;
58  int startHandlerFailed;
59  char * nsPrefix;
60  char * nsUri;
61  int nsUriLength;
62  void *clientData;
63  SubElementDataT * subElements;
64  HandlerSetT * parentHandler;
65  int charDataBufferUsed;
66  char *charDataBuffer;
67  UnexpectedElementHandlerT unexpectedElementHandler;
68  } ParseContextT;
69 
70  signed short readZippedXML(char* filename, char* nsUri, void* userData, SubElementDataT* rootElement, UnexpectedElementHandlerT z_unexpectedElementHandler, ParseErrorHandlerT z_parseErrorHandler);
71 
72 
73  /* dummy handler - just skips character data */
74  void nullCharacterDataHandler (void *data, const XML_Char *s, int len);
75 
76  void nullStartHandler(void *data, const char *elementName, const char **attr);
77  void nullEndHandler(void *data, const char *elementName);
78 #ifdef __cplusplus
79 }
80 #endif /* __cplusplus */
Definition: zippedXmlReader.h:32
Definition: zippedXmlReader.h:42
Definition: zippedXmlReader.h:53