Annotation of XML/parser.h, revision 1.36

1.1       veillard    1: /*
                      2:  * parser.h : constants and stuff related to the XML parser.
1.6       veillard    3:  *
                      4:  * See Copyright for the status of this software.
                      5:  *
1.23      daniel      6:  * Daniel.Veillard@w3.org
1.1       veillard    7:  */
                      8: 
                      9: #ifndef __XML_PARSER_H__
                     10: #define __XML_PARSER_H__
                     11: 
1.2       veillard   12: #include "tree.h"
1.32      daniel     13: #include "xmlIO.h"
1.2       veillard   14: 
1.7       daniel     15: #ifdef __cplusplus
                     16: extern "C" {
                     17: #endif
                     18: 
1.1       veillard   19: /*
                     20:  * Constants.
                     21:  */
                     22: #define XML_DEFAULT_VERSION    "1.0"
                     23: 
1.25      daniel     24: typedef void (* xmlParserInputDeallocate)(CHAR *);
1.14      daniel     25: typedef struct xmlParserInput {
1.32      daniel     26:     /* Input buffer */
                     27:     xmlParserInputBufferPtr buf;      /* UTF-8 encoded buffer */
                     28: 
1.14      daniel     29:     const char *filename;             /* The file analyzed, if any */
1.36    ! daniel     30:     const char *directory;            /* the directory/base of teh file */
1.14      daniel     31:     const CHAR *base;                 /* Base of the array to parse */
                     32:     const CHAR *cur;                  /* Current char being parsed */
                     33:     int line;                         /* Current line */
                     34:     int col;                          /* Current column */
1.35      daniel     35:     int consumed;                     /* How many CHARs were already consumed */
1.25      daniel     36:     xmlParserInputDeallocate free;    /* function to deallocate the base */
1.24      daniel     37: } xmlParserInput;
                     38: typedef xmlParserInput *xmlParserInputPtr;
1.7       daniel     39: 
1.24      daniel     40: typedef struct _xmlParserNodeInfo {
1.13      daniel     41:   const struct xmlNode* node;
                     42:   /* Position & line # that text that created the node begins & ends on */
                     43:   unsigned long begin_pos;
                     44:   unsigned long begin_line;
                     45:   unsigned long end_pos;
                     46:   unsigned long end_line;
1.24      daniel     47: } _xmlParserNodeInfo;
                     48: typedef _xmlParserNodeInfo xmlParserNodeInfo;
1.13      daniel     49: 
                     50: typedef struct xmlParserNodeInfoSeq {
                     51:   unsigned long maximum;
                     52:   unsigned long length;
                     53:   xmlParserNodeInfo* buffer;
1.24      daniel     54: } _xmlParserNodeInfoSeq;
                     55: typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
                     56: typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
1.13      daniel     57: 
1.24      daniel     58: typedef struct _xmlParserCtxt {
1.17      daniel     59:     struct xmlSAXHandler *sax;        /* The SAX handler */
1.27      daniel     60:     void            *userData;        /* the document being built */
                     61:     xmlDocPtr           myDoc;        /* the document being built */
1.22      daniel     62:     int            wellFormed;        /* is the document well formed */
1.30      daniel     63:     int       replaceEntities;        /* shall we replace entities ? */
1.27      daniel     64:     const CHAR     *version;         /* the XML version string */
                     65:     const CHAR     *encoding;         /* encoding, if any */
                     66:     int             standalone;       /* standalone document */
1.33      daniel     67:     int                   html;       /* are we parsing an HTML document */
1.16      daniel     68: 
1.14      daniel     69:     /* Input stream stack */
1.15      daniel     70:     xmlParserInputPtr  input;         /* Current input stream */
1.14      daniel     71:     int                inputNr;       /* Number of current input streams */
                     72:     int                inputMax;      /* Max number of input streams */
                     73:     xmlParserInputPtr *inputTab;      /* stack of inputs */
1.15      daniel     74: 
                     75:     /* Node analysis stack */
                     76:     xmlNodePtr         node;          /* Current parsed Node */
                     77:     int                nodeNr;        /* Depth of the parsing stack */
                     78:     int                nodeMax;       /* Max depth of the parsing stack */
                     79:     xmlNodePtr        *nodeTab;       /* array of nodes */
1.14      daniel     80: 
1.13      daniel     81:     int record_info;                  /* Whether node info should be kept */
                     82:     xmlParserNodeInfoSeq node_seq;    /* info about each node parsed */
1.24      daniel     83: } _xmlParserCtxt;
                     84: typedef _xmlParserCtxt xmlParserCtxt;
                     85: typedef xmlParserCtxt *xmlParserCtxtPtr;
1.7       daniel     86: 
                     87: /*
1.17      daniel     88:  * a SAX Locator.
                     89:  */
                     90: 
                     91: typedef struct xmlSAXLocator {
1.28      daniel     92:     const CHAR *(*getPublicId)(void *ctx);
                     93:     const CHAR *(*getSystemId)(void *ctx);
                     94:     int (*getLineNumber)(void *ctx);
                     95:     int (*getColumnNumber)(void *ctx);
1.24      daniel     96: } _xmlSAXLocator;
                     97: typedef _xmlSAXLocator xmlSAXLocator;
                     98: typedef xmlSAXLocator *xmlSAXLocatorPtr;
1.17      daniel     99: 
                    100: /*
                    101:  * a SAX Exception.
                    102:  */
                    103: 
1.27      daniel    104: #include "entities.h"
                    105: 
1.28      daniel    106: typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx,
1.18      daniel    107:                            const CHAR *publicId, const CHAR *systemId);
1.28      daniel    108: typedef void (*internalSubsetSAXFunc) (void *ctx, const CHAR *name,
1.27      daniel    109:                             const CHAR *ExternalID, const CHAR *SystemID);
1.28      daniel    110: typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx,
1.27      daniel    111:                             const CHAR *name);
1.28      daniel    112: typedef void (*entityDeclSAXFunc) (void *ctx,
1.27      daniel    113:                             const CHAR *name, int type, const CHAR *publicId,
                    114:                            const CHAR *systemId, CHAR *content);
1.28      daniel    115: typedef void (*notationDeclSAXFunc)(void *ctx, const CHAR *name,
1.18      daniel    116:                            const CHAR *publicId, const CHAR *systemId);
1.28      daniel    117: typedef void (*attributeDeclSAXFunc)(void *ctx, const CHAR *elem,
1.27      daniel    118:                             const CHAR *name, int type, int def,
                    119:                            const CHAR *defaultValue, xmlEnumerationPtr tree);
1.28      daniel    120: typedef void (*elementDeclSAXFunc)(void *ctx, const CHAR *name,
1.27      daniel    121:                            int type, xmlElementContentPtr content);
1.28      daniel    122: typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
1.18      daniel    123:                             const CHAR *name, const CHAR *publicId,
                    124:                            const CHAR *systemId, const CHAR *notationName);
1.28      daniel    125: typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
1.18      daniel    126:                             xmlSAXLocatorPtr loc);
1.28      daniel    127: typedef void (*startDocumentSAXFunc) (void *ctx);
                    128: typedef void (*endDocumentSAXFunc) (void *ctx);
                    129: typedef void (*startElementSAXFunc) (void *ctx, const CHAR *name,
1.27      daniel    130:                             const CHAR **atts);
1.28      daniel    131: typedef void (*endElementSAXFunc) (void *ctx, const CHAR *name);
                    132: typedef void (*attributeSAXFunc) (void *ctx, const CHAR *name,
1.19      daniel    133:                                   const CHAR *value);
1.28      daniel    134: typedef void (*referenceSAXFunc) (void *ctx, const CHAR *name);
                    135: typedef void (*charactersSAXFunc) (void *ctx, const CHAR *ch,
1.27      daniel    136:                            int len);
1.28      daniel    137: typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
1.27      daniel    138:                            const CHAR *ch, int len);
1.28      daniel    139: typedef void (*processingInstructionSAXFunc) (void *ctx,
1.18      daniel    140:                             const CHAR *target, const CHAR *data);
1.28      daniel    141: typedef void (*commentSAXFunc) (void *ctx, const CHAR *value);
                    142: typedef void (*warningSAXFunc) (void *ctx, const char *msg, ...);
                    143: typedef void (*errorSAXFunc) (void *ctx, const char *msg, ...);
                    144: typedef void (*fatalErrorSAXFunc) (void *ctx, const char *msg, ...);
                    145: typedef int (*isStandaloneSAXFunc) (void *ctx);
                    146: typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
                    147: typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
1.18      daniel    148: 
1.17      daniel    149: typedef struct xmlSAXHandler {
1.27      daniel    150:     internalSubsetSAXFunc internalSubset;
                    151:     isStandaloneSAXFunc isStandalone;
                    152:     hasInternalSubsetSAXFunc hasInternalSubset;
                    153:     hasExternalSubsetSAXFunc hasExternalSubset;
1.18      daniel    154:     resolveEntitySAXFunc resolveEntity;
1.27      daniel    155:     getEntitySAXFunc getEntity;
                    156:     entityDeclSAXFunc entityDecl;
1.18      daniel    157:     notationDeclSAXFunc notationDecl;
1.27      daniel    158:     attributeDeclSAXFunc attributeDecl;
                    159:     elementDeclSAXFunc elementDecl;
1.18      daniel    160:     unparsedEntityDeclSAXFunc unparsedEntityDecl;
                    161:     setDocumentLocatorSAXFunc setDocumentLocator;
                    162:     startDocumentSAXFunc startDocument;
                    163:     endDocumentSAXFunc endDocument;
                    164:     startElementSAXFunc startElement;
                    165:     endElementSAXFunc endElement;
1.27      daniel    166:     referenceSAXFunc reference;
1.18      daniel    167:     charactersSAXFunc characters;
                    168:     ignorableWhitespaceSAXFunc ignorableWhitespace;
                    169:     processingInstructionSAXFunc processingInstruction;
1.27      daniel    170:     commentSAXFunc comment;
1.18      daniel    171:     warningSAXFunc warning;
                    172:     errorSAXFunc error;
                    173:     fatalErrorSAXFunc fatalError;
1.24      daniel    174: } xmlSAXHandler;
                    175: typedef xmlSAXHandler *xmlSAXHandlerPtr;
1.17      daniel    176: 
                    177: /*
                    178:  * Global variables: just the SAX interface tables we are looking for full
1.33      daniel    179:  *      reentrancy of the code and version infos.
1.17      daniel    180:  */
1.33      daniel    181: extern const char *xmlParserVersion;
                    182: 
1.19      daniel    183: extern xmlSAXLocator xmlDefaultSAXLocator;
                    184: extern xmlSAXHandler xmlDefaultSAXHandler;
1.33      daniel    185: extern xmlSAXHandler htmlDefaultSAXHandler;
1.19      daniel    186: 
                    187: #include "entities.h"
1.26      daniel    188: #include "xml-error.h"
1.35      daniel    189: 
                    190: /*
                    191:  * Input functions
                    192:  */
                    193: 
                    194: int xmlParserInputRead(xmlParserInputPtr in, int len);
                    195: int xmlParserInputGrow(xmlParserInputPtr in, int len);
1.17      daniel    196: 
                    197: /*
1.22      daniel    198:  * CHAR handling
1.2       veillard  199:  */
1.24      daniel    200: CHAR *xmlStrdup(const CHAR *cur);
                    201: CHAR *xmlStrndup(const CHAR *cur, int len);
1.34      daniel    202: CHAR *xmlStrsub(const CHAR *str, int start, int len);
                    203: const CHAR *xmlStrchr(const CHAR *str, CHAR val);
                    204: const CHAR *xmlStrstr(const CHAR *str, CHAR *val);
1.24      daniel    205: int xmlStrcmp(const CHAR *str1, const CHAR *str2);
                    206: int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
                    207: int xmlStrlen(const CHAR *str);
                    208: CHAR *xmlStrcat(CHAR *cur, const CHAR *add);
                    209: CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len);
1.9       daniel    210: 
1.22      daniel    211: /*
                    212:  * Interfaces
                    213:  */
1.24      daniel    214: xmlDocPtr xmlParseDoc(CHAR *cur);
                    215: xmlDocPtr xmlParseMemory(char *buffer, int size);
                    216: xmlDocPtr xmlParseFile(const char *filename);
1.31      daniel    217: int xmlSubstituteEntitiesDefault(int val);
1.22      daniel    218: 
                    219: /*
                    220:  * Recovery mode 
                    221:  */
1.24      daniel    222: xmlDocPtr xmlRecoverDoc(CHAR *cur);
                    223: xmlDocPtr xmlRecoverMemory(char *buffer, int size);
                    224: xmlDocPtr xmlRecoverFile(const char *filename);
1.22      daniel    225: 
                    226: /*
                    227:  * Internal routines
                    228:  */
1.24      daniel    229: int xmlParseDocument(xmlParserCtxtPtr ctxt);
                    230: xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery);
                    231: xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer,
1.22      daniel    232:                                    int size, int recovery);
1.24      daniel    233: xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
1.22      daniel    234:                                  int recovery);
1.29      daniel    235: xmlDtdPtr xmlParseDTD(const CHAR *ExternalID, const CHAR *SystemID);
                    236: xmlDtdPtr xmlSAXParseDTD(xmlSAXHandlerPtr sax, const CHAR *ExternalID,
                    237:                          const CHAR *SystemID);
1.24      daniel    238: void xmlInitParserCtxt(xmlParserCtxtPtr ctxt);
                    239: void xmlClearParserCtxt(xmlParserCtxtPtr ctxt);
                    240: void xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const CHAR* buffer,
1.9       daniel    241:                                     const char* filename);
                    242: 
1.24      daniel    243: const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* ctxt,
                    244:                                                const xmlNode* node);
                    245: void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
                    246: void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
1.13      daniel    247: unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
                    248:                                          const xmlNode* node);
1.24      daniel    249: void xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
                    250:                           const xmlParserNodeInfo* info);
1.7       daniel    251: 
1.24      daniel    252: void xmlDefaultSAXHandlerInit(void);
1.33      daniel    253: void htmlDefaultSAXHandlerInit(void);
1.7       daniel    254: #ifdef __cplusplus
                    255: }
                    256: #endif
1.1       veillard  257: 
                    258: #endif /* __XML_PARSER_H__ */
                    259: 

Webmaster