1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/* $Id: xmlparser.h,v 1.39 2000/10/26 15:13:50 richard Exp $ */
#ifndef XMLPARSER_H
#define XMLPARSER_H
#include "dtd.h"
#include "input.h"
#include "rxputil.h"
#include "namespaces.h"
#ifdef FOR_LT
#include "lt-hash.h"
typedef HashTab *HashTable;
#else
#include "hash.h"
#endif
/* Typedefs */
typedef struct parser_state *Parser;
typedef struct attribute *Attribute;
typedef struct xbit *XBit;
typedef void CallbackProc(XBit bit, void *arg);
typedef InputSource EntityOpenerProc(Entity e, void *arg);
/* Bits */
enum xbit_type {
XBIT_dtd,
XBIT_start, XBIT_empty, XBIT_end, XBIT_eof, XBIT_pcdata,
XBIT_pi, XBIT_comment, XBIT_cdsect,
XBIT_error, XBIT_warning, XBIT_none,
XBIT_enum_count
};
typedef enum xbit_type XBitType;
extern XML_API const char8 *XBitTypeName[XBIT_enum_count];
enum white_space_mode {
WSM_unspecified, WSM_default, WSM_preserve
};
typedef enum white_space_mode WhiteSpaceMode;
struct namespace_binding {
const Char *prefix; /* points into an attribute name, or is null */
Namespace RXP_NAMESPACE; /* that's namespace or name_space in C++ */
struct namespace_binding *parent;
};
typedef struct namespace_binding *NamespaceBinding;
struct attribute {
AttributeDefinition definition; /* The definition of this attribute */
NSAttributeDefinition ns_definition;
Char *value; /* The (possibly normalised) value */
int quoted; /* Was it quoted? */
struct attribute *next; /* The next attribute or null */
};
struct xbit {
Entity entity;
int byte_offset;
enum xbit_type type;
char8 *s1;
Char *S1, *S2;
int i1;
Attribute attributes;
ElementDefinition element_definition;
WhiteSpaceMode wsm;
NamespaceBinding ns_dict; /* Linked list of namespace bindings */
int nsc; /* Count of local ns records */
int nsowned; /* True if ns recs should be freed with bit */
NSElementDefinition ns_element_definition;
/* Null if no prefix and no default ns */
#ifndef FOR_LT
int nchildren;
struct xbit *parent;
struct xbit **children;
#endif
};
#define pcdata_chars S1
#define pcdata_ignorable_whitespace i1
#define pi_name S1
#define pi_chars S2
#define comment_chars S1
#define cdsect_chars S1
#define error_message s1
/* Parser flags */
enum parser_flag {
ExpandCharacterEntities,
ExpandGeneralEntities,
XMLSyntax,
XMLPredefinedEntities,
ErrorOnUnquotedAttributeValues,
NormaliseAttributeValues,
ErrorOnBadCharacterEntities,
ErrorOnUndefinedEntities,
ReturnComments,
CaseInsensitive,
ErrorOnUndefinedElements,
ErrorOnUndefinedAttributes,
WarnOnRedefinitions,
TrustSDD,
XMLExternalIDs,
ReturnDefaultedAttributes,
MergePCData,
XMLMiscWFErrors,
XMLStrictWFErrors,
AllowMultipleElements,
MaintainElementStack,
IgnoreEntities,
XMLLessThan,
IgnorePlacementErrors,
Validate,
ErrorOnValidityErrors,
XMLSpace,
XMLNamespaces,
NoNoDTDWarning,
SimpleErrorFormat,
AllowUndeclaredNSAttributes,
RelaxedAny
};
typedef enum parser_flag ParserFlag;
#define NormalizeAttributeValues NormaliseAttributeValues
/* Parser */
enum parse_state
{PS_prolog1, PS_prolog2, PS_validate_dtd,
PS_body, PS_validate_final, PS_epilog, PS_end, PS_error};
struct element_info {
ElementDefinition definition;
NSElementDefinition ns_definition;
Entity entity;
FSMNode context;
WhiteSpaceMode wsm;
NamespaceBinding ns;
int nsc;
};
struct parser_state {
enum parse_state state;
int seen_validity_error;
Entity document_entity;
int have_dtd; /* True if dtd has been processed */
StandaloneDeclaration standalone;
struct input_source *source;
Char *name, *pbuf, *save_pbuf;
char8 *transbuf;
char8 errbuf[400]; /* For error messages; fixed size is bad but
we don't want to fail if we can't malloc */
char8 escbuf[2][15];
int namelen, pbufsize, pbufnext, save_pbufsize, save_pbufnext;
struct xbit xbit;
int peeked;
Dtd dtd; /* The document's DTD */
CallbackProc *dtd_callback;
CallbackProc *warning_callback;
EntityOpenerProc *entity_opener;
unsigned int flags;
Vector(struct element_info, element_stack);
struct namespace_binding base_ns;
void *callback_arg;
int external_pe_depth; /* To keep track of whether we're in the */
/* internal subset: 0 <=> yes */
HashTable id_table;
};
XML_API int init_parser(void);
XML_API void deinit_parser(void);
XML_API Parser NewParser(void);
XML_API void FreeParser(Parser p);
XML_API Entity ParserRootEntity(Parser p);
XML_API InputSource ParserRootSource(Parser p);
XML_API XBit ReadXBit(Parser p);
XML_API XBit PeekXBit(Parser p);
XML_API void FreeXBit(XBit xbit);
#ifndef FOR_LT
XBit ReadXTree(Parser p);
void FreeXTree(XBit tree);
#endif
XML_API XBit ParseDtd(Parser p, Entity e);
XML_API void ParserSetWarningCallback(Parser p, CallbackProc cb);
XML_API void ParserSetDtdCallback(Parser p, CallbackProc cb);
XML_API void ParserSetEntityOpener(Parser p, EntityOpenerProc opener);
XML_API void ParserSetCallbackArg(Parser p, void *arg);
XML_API int ParserPush(Parser p, InputSource source);
XML_API void ParserPop(Parser p);
XML_API void ParserSetFlag(Parser p, ParserFlag flag, int value);
#define ParserGetFlag(p, flag) ((p)->flags & (1u << (flag)))
XML_API void ParserPerror(Parser p, XBit bit);
#endif /* XMLPARSER_H */
|