Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * parser.c : an XML 1.0 non-verifying parser |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6 | * Daniel.Veillard@w3.org |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifdef WIN32 |
| 10 | #define HAVE_FCNTL_H |
| 11 | #include <io.h> |
| 12 | #else |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 13 | #include "config.h" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 14 | #endif |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 15 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 16 | #include <stdio.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 17 | #include <string.h> /* for memset() only */ |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 18 | #ifdef HAVE_CTYPE_H |
| 19 | #include <ctype.h> |
| 20 | #endif |
| 21 | #ifdef HAVE_STDLIB_H |
Seth Alves | e7f12e6 | 1998-10-01 20:51:15 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 23 | #endif |
| 24 | #ifdef HAVE_SYS_STAT_H |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 25 | #include <sys/stat.h> |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 26 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 27 | #ifdef HAVE_FCNTL_H |
| 28 | #include <fcntl.h> |
| 29 | #endif |
| 30 | #ifdef HAVE_UNISTD_H |
| 31 | #include <unistd.h> |
| 32 | #endif |
| 33 | #ifdef HAVE_ZLIB_H |
| 34 | #include <zlib.h> |
| 35 | #endif |
| 36 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 37 | #include "xmlmemory.h" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 38 | #include "tree.h" |
| 39 | #include "parser.h" |
| 40 | #include "entities.h" |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 41 | #include "encoding.h" |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 42 | #include "valid.h" |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 43 | #include "parserInternals.h" |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 44 | #include "xmlIO.h" |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 45 | #include "xml-error.h" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 46 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 47 | const char *xmlParserVersion = LIBXML_VERSION; |
| 48 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 49 | |
| 50 | /************************************************************************ |
| 51 | * * |
| 52 | * Input handling functions for progressive parsing * |
| 53 | * * |
| 54 | ************************************************************************/ |
| 55 | |
| 56 | /* #define DEBUG_INPUT */ |
| 57 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 58 | #define INPUT_CHUNK 250 |
| 59 | /* we need to keep enough input to show errors in context */ |
| 60 | #define LINE_LEN 80 |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 61 | |
| 62 | #ifdef DEBUG_INPUT |
| 63 | #define CHECK_BUFFER(in) check_buffer(in) |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 64 | |
| 65 | void check_buffer(xmlParserInputPtr in) { |
| 66 | if (in->base != in->buf->buffer->content) { |
| 67 | fprintf(stderr, "xmlParserInput: base mismatch problem\n"); |
| 68 | } |
| 69 | if (in->cur < in->base) { |
| 70 | fprintf(stderr, "xmlParserInput: cur < base problem\n"); |
| 71 | } |
| 72 | if (in->cur > in->base + in->buf->buffer->use) { |
| 73 | fprintf(stderr, "xmlParserInput: cur > base + use problem\n"); |
| 74 | } |
| 75 | fprintf(stderr,"buffer %x : content %x, cur %d, use %d, size %d\n", |
| 76 | (int) in, (int) in->buf->buffer->content, in->cur - in->base, |
| 77 | in->buf->buffer->use, in->buf->buffer->size); |
| 78 | } |
| 79 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 80 | #else |
| 81 | #define CHECK_BUFFER(in) |
| 82 | #endif |
| 83 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * xmlParserInputRead: |
| 87 | * @in: an XML parser input |
| 88 | * @len: an indicative size for the lookahead |
| 89 | * |
| 90 | * This function refresh the input for the parser. It doesn't try to |
| 91 | * preserve pointers to the input buffer, and discard already read data |
| 92 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 93 | * Returns the number of xmlChars read, or -1 in case of error, 0 indicate the |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 94 | * end of this entity |
| 95 | */ |
| 96 | int |
| 97 | xmlParserInputRead(xmlParserInputPtr in, int len) { |
| 98 | int ret; |
| 99 | int used; |
| 100 | int index; |
| 101 | |
| 102 | #ifdef DEBUG_INPUT |
| 103 | fprintf(stderr, "Read\n"); |
| 104 | #endif |
| 105 | if (in->buf == NULL) return(-1); |
| 106 | if (in->base == NULL) return(-1); |
| 107 | if (in->cur == NULL) return(-1); |
| 108 | if (in->buf->buffer == NULL) return(-1); |
| 109 | |
| 110 | CHECK_BUFFER(in); |
| 111 | |
| 112 | used = in->cur - in->buf->buffer->content; |
| 113 | ret = xmlBufferShrink(in->buf->buffer, used); |
| 114 | if (ret > 0) { |
| 115 | in->cur -= ret; |
| 116 | in->consumed += ret; |
| 117 | } |
| 118 | ret = xmlParserInputBufferRead(in->buf, len); |
| 119 | if (in->base != in->buf->buffer->content) { |
| 120 | /* |
| 121 | * the buffer has been realloced |
| 122 | */ |
| 123 | index = in->cur - in->base; |
| 124 | in->base = in->buf->buffer->content; |
| 125 | in->cur = &in->buf->buffer->content[index]; |
| 126 | } |
| 127 | |
| 128 | CHECK_BUFFER(in); |
| 129 | |
| 130 | return(ret); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * xmlParserInputGrow: |
| 135 | * @in: an XML parser input |
| 136 | * @len: an indicative size for the lookahead |
| 137 | * |
| 138 | * This function increase the input for the parser. It tries to |
| 139 | * preserve pointers to the input buffer, and keep already read data |
| 140 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 141 | * Returns the number of xmlChars read, or -1 in case of error, 0 indicate the |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 142 | * end of this entity |
| 143 | */ |
| 144 | int |
| 145 | xmlParserInputGrow(xmlParserInputPtr in, int len) { |
| 146 | int ret; |
| 147 | int index; |
| 148 | |
| 149 | #ifdef DEBUG_INPUT |
| 150 | fprintf(stderr, "Grow\n"); |
| 151 | #endif |
| 152 | if (in->buf == NULL) return(-1); |
| 153 | if (in->base == NULL) return(-1); |
| 154 | if (in->cur == NULL) return(-1); |
| 155 | if (in->buf->buffer == NULL) return(-1); |
| 156 | |
| 157 | CHECK_BUFFER(in); |
| 158 | |
| 159 | index = in->cur - in->base; |
| 160 | if (in->buf->buffer->use > index + INPUT_CHUNK) { |
| 161 | |
| 162 | CHECK_BUFFER(in); |
| 163 | |
| 164 | return(0); |
| 165 | } |
| 166 | ret = xmlParserInputBufferGrow(in->buf, len); |
| 167 | if (in->base != in->buf->buffer->content) { |
| 168 | /* |
| 169 | * the buffer has been realloced |
| 170 | */ |
| 171 | index = in->cur - in->base; |
| 172 | in->base = in->buf->buffer->content; |
| 173 | in->cur = &in->buf->buffer->content[index]; |
| 174 | } |
| 175 | |
| 176 | CHECK_BUFFER(in); |
| 177 | |
| 178 | return(ret); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * xmlParserInputShrink: |
| 183 | * @in: an XML parser input |
| 184 | * |
| 185 | * This function removes used input for the parser. |
| 186 | */ |
| 187 | void |
| 188 | xmlParserInputShrink(xmlParserInputPtr in) { |
| 189 | int used; |
| 190 | int ret; |
| 191 | int index; |
| 192 | |
| 193 | #ifdef DEBUG_INPUT |
| 194 | fprintf(stderr, "Shrink\n"); |
| 195 | #endif |
| 196 | if (in->buf == NULL) return; |
| 197 | if (in->base == NULL) return; |
| 198 | if (in->cur == NULL) return; |
| 199 | if (in->buf->buffer == NULL) return; |
| 200 | |
| 201 | CHECK_BUFFER(in); |
| 202 | |
| 203 | used = in->cur - in->buf->buffer->content; |
| 204 | if (used > INPUT_CHUNK) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 205 | ret = xmlBufferShrink(in->buf->buffer, used - LINE_LEN); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 206 | if (ret > 0) { |
| 207 | in->cur -= ret; |
| 208 | in->consumed += ret; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | CHECK_BUFFER(in); |
| 213 | |
| 214 | if (in->buf->buffer->use > INPUT_CHUNK) { |
| 215 | return; |
| 216 | } |
| 217 | xmlParserInputBufferRead(in->buf, 2 * INPUT_CHUNK); |
| 218 | if (in->base != in->buf->buffer->content) { |
| 219 | /* |
| 220 | * the buffer has been realloced |
| 221 | */ |
| 222 | index = in->cur - in->base; |
| 223 | in->base = in->buf->buffer->content; |
| 224 | in->cur = &in->buf->buffer->content[index]; |
| 225 | } |
| 226 | |
| 227 | CHECK_BUFFER(in); |
| 228 | } |
| 229 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 230 | /************************************************************************ |
| 231 | * * |
| 232 | * Parser stacks related functions and macros * |
| 233 | * * |
| 234 | ************************************************************************/ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 235 | |
| 236 | int xmlSubstituteEntitiesDefaultValue = 0; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 237 | int xmlDoValidityCheckingDefaultValue = 0; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 238 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 239 | /* |
| 240 | * Generic function for accessing stacks in the Parser Context |
| 241 | */ |
| 242 | |
| 243 | #define PUSH_AND_POP(type, name) \ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 244 | extern int name##Push(xmlParserCtxtPtr ctxt, type value) { \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 245 | if (ctxt->name##Nr >= ctxt->name##Max) { \ |
| 246 | ctxt->name##Max *= 2; \ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 247 | ctxt->name##Tab = (void *) xmlRealloc(ctxt->name##Tab, \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 248 | ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \ |
| 249 | if (ctxt->name##Tab == NULL) { \ |
| 250 | fprintf(stderr, "realloc failed !\n"); \ |
| 251 | exit(1); \ |
| 252 | } \ |
| 253 | } \ |
| 254 | ctxt->name##Tab[ctxt->name##Nr] = value; \ |
| 255 | ctxt->name = value; \ |
| 256 | return(ctxt->name##Nr++); \ |
| 257 | } \ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 258 | extern type name##Pop(xmlParserCtxtPtr ctxt) { \ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 259 | type ret; \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 260 | if (ctxt->name##Nr <= 0) return(0); \ |
| 261 | ctxt->name##Nr--; \ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 262 | if (ctxt->name##Nr > 0) \ |
| 263 | ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \ |
| 264 | else \ |
| 265 | ctxt->name = NULL; \ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 266 | ret = ctxt->name##Tab[ctxt->name##Nr]; \ |
| 267 | ctxt->name##Tab[ctxt->name##Nr] = 0; \ |
| 268 | return(ret); \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 269 | } \ |
| 270 | |
| 271 | PUSH_AND_POP(xmlParserInputPtr, input) |
| 272 | PUSH_AND_POP(xmlNodePtr, node) |
| 273 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 274 | /* |
| 275 | * Macros for accessing the content. Those should be used only by the parser, |
| 276 | * and not exported. |
| 277 | * |
| 278 | * Dirty macros, i.e. one need to make assumption on the context to use them |
| 279 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 280 | * CUR_PTR return the current pointer to the xmlChar to be parsed. |
| 281 | * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 282 | * in ISO-Latin or UTF-8, and the current 16 bit value if compiled |
| 283 | * in UNICODE mode. This should be used internally by the parser |
| 284 | * only to compare to ASCII values otherwise it would break when |
| 285 | * running with UTF-8 encoding. |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 286 | * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 287 | * to compare on ASCII based substring. |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 288 | * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 289 | * strings within the parser. |
| 290 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 291 | * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 292 | * |
| 293 | * CURRENT Returns the current char value, with the full decoding of |
| 294 | * UTF-8 if we are using this mode. It returns an int. |
| 295 | * NEXT Skip to the next character, this does the proper decoding |
| 296 | * in UTF-8 mode. It also pop-up unfinished entities on the fly. |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 297 | * COPY(to) copy one char to *to, increment CUR_PTR and to accordingly |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 298 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 299 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 300 | #define CUR (ctxt->token ? ctxt->token : (*ctxt->input->cur)) |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 301 | #define SKIP(val) ctxt->input->cur += (val) |
| 302 | #define NXT(val) ctxt->input->cur[(val)] |
| 303 | #define CUR_PTR ctxt->input->cur |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 304 | #define SHRINK xmlParserInputShrink(ctxt->input); \ |
| 305 | if ((*ctxt->input->cur == 0) && \ |
| 306 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ |
| 307 | xmlPopInput(ctxt) |
| 308 | |
| 309 | #define GROW xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \ |
| 310 | if ((*ctxt->input->cur == 0) && \ |
| 311 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ |
| 312 | xmlPopInput(ctxt) |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 313 | |
| 314 | #define SKIP_BLANKS \ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 315 | do { \ |
| 316 | while (IS_BLANK(CUR)) NEXT; \ |
| 317 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ |
| 318 | if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); \ |
| 319 | } while (IS_BLANK(CUR)); |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 320 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 321 | #define CURRENT (*ctxt->input->cur) |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 322 | #define NEXT { \ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 323 | if (ctxt->token != 0) ctxt->token = 0; \ |
| 324 | else { \ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 325 | if ((*ctxt->input->cur == 0) && \ |
| 326 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) { \ |
| 327 | xmlPopInput(ctxt); \ |
| 328 | } else { \ |
| 329 | if (*(ctxt->input->cur) == '\n') { \ |
| 330 | ctxt->input->line++; ctxt->input->col = 1; \ |
| 331 | } else ctxt->input->col++; \ |
| 332 | ctxt->input->cur++; \ |
| 333 | if (*ctxt->input->cur == 0) \ |
| 334 | xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 335 | } \ |
| 336 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ |
| 337 | if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); \ |
| 338 | }} |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 339 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 340 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 341 | /************************************************************************ |
| 342 | * * |
| 343 | * Commodity functions to handle entities processing * |
| 344 | * * |
| 345 | ************************************************************************/ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 346 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 347 | /** |
| 348 | * xmlPopInput: |
| 349 | * @ctxt: an XML parser context |
| 350 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 351 | * xmlPopInput: the current input pointed by ctxt->input came to an end |
| 352 | * pop it and return the next char. |
| 353 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 354 | * Returns the current xmlChar in the parser context |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 355 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 356 | xmlChar |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 357 | xmlPopInput(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 358 | if (ctxt->inputNr == 1) return(0); /* End of main Input */ |
Daniel Veillard | bc50b59 | 1999-03-01 12:28:53 +0000 | [diff] [blame] | 359 | xmlFreeInputStream(inputPop(ctxt)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 360 | if ((*ctxt->input->cur == 0) && |
| 361 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) |
| 362 | return(xmlPopInput(ctxt)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 363 | return(CUR); |
| 364 | } |
| 365 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 366 | /** |
| 367 | * xmlPushInput: |
| 368 | * @ctxt: an XML parser context |
| 369 | * @input: an XML parser input fragment (entity, XML fragment ...). |
| 370 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 371 | * xmlPushInput: switch to a new input stream which is stacked on top |
| 372 | * of the previous one(s). |
| 373 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 374 | void |
| 375 | xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 376 | if (input == NULL) return; |
| 377 | inputPush(ctxt, input); |
| 378 | } |
| 379 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 380 | /** |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 381 | * xmlFreeInputStream: |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 382 | * @input: an xmlP arserInputPtr |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 383 | * |
| 384 | * Free up an input stream. |
| 385 | */ |
| 386 | void |
| 387 | xmlFreeInputStream(xmlParserInputPtr input) { |
| 388 | if (input == NULL) return; |
| 389 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 390 | if (input->filename != NULL) xmlFree((char *) input->filename); |
| 391 | if (input->directory != NULL) xmlFree((char *) input->directory); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 392 | if ((input->free != NULL) && (input->base != NULL)) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 393 | input->free((xmlChar *) input->base); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 394 | if (input->buf != NULL) |
| 395 | xmlFreeParserInputBuffer(input->buf); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 396 | memset(input, -1, sizeof(xmlParserInput)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 397 | xmlFree(input); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 401 | * xmlNewInputStream: |
| 402 | * @ctxt: an XML parser context |
| 403 | * |
| 404 | * Create a new input stream structure |
| 405 | * Returns the new input stream or NULL |
| 406 | */ |
| 407 | xmlParserInputPtr |
| 408 | xmlNewInputStream(xmlParserCtxtPtr ctxt) { |
| 409 | xmlParserInputPtr input; |
| 410 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 411 | input = (xmlParserInputPtr) xmlMalloc(sizeof(xmlParserInput)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 412 | if (input == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 413 | ctxt->errNo = XML_ERR_NO_MEMORY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 414 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 415 | ctxt->sax->error(ctxt->userData, |
| 416 | "malloc: couldn't allocate a new input stream\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 417 | ctxt->errNo = XML_ERR_NO_MEMORY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 418 | return(NULL); |
| 419 | } |
| 420 | input->filename = NULL; |
| 421 | input->directory = NULL; |
| 422 | input->base = NULL; |
| 423 | input->cur = NULL; |
| 424 | input->buf = NULL; |
| 425 | input->line = 1; |
| 426 | input->col = 1; |
| 427 | input->buf = NULL; |
| 428 | input->free = NULL; |
| 429 | input->consumed = 0; |
| 430 | return(input); |
| 431 | } |
| 432 | |
| 433 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 434 | * xmlNewEntityInputStream: |
| 435 | * @ctxt: an XML parser context |
| 436 | * @entity: an Entity pointer |
| 437 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 438 | * Create a new input stream based on an xmlEntityPtr |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 439 | * |
| 440 | * Returns the new input stream or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 441 | */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 442 | xmlParserInputPtr |
| 443 | xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 444 | xmlParserInputPtr input; |
| 445 | |
| 446 | if (entity == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 447 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 448 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 449 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 450 | "internal: xmlNewEntityInputStream entity = NULL\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 451 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 452 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 453 | } |
| 454 | if (entity->content == NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 455 | switch (entity->type) { |
| 456 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 457 | ctxt->errNo = XML_ERR_UNPARSED_ENTITY; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 458 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 459 | ctxt->sax->error(ctxt->userData, |
| 460 | "xmlNewEntityInputStream unparsed entity !\n"); |
| 461 | break; |
| 462 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 463 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 464 | return(xmlLoadExternalEntity((char *) entity->SystemID, |
| 465 | (char *) entity->ExternalID, ctxt->input)); |
| 466 | case XML_INTERNAL_GENERAL_ENTITY: |
| 467 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 468 | ctxt->sax->error(ctxt->userData, |
| 469 | "Internal entity %s without content !\n", entity->name); |
| 470 | break; |
| 471 | case XML_INTERNAL_PARAMETER_ENTITY: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 472 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 473 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 474 | ctxt->sax->error(ctxt->userData, |
| 475 | "Internal parameter entity %s without content !\n", entity->name); |
| 476 | break; |
| 477 | case XML_INTERNAL_PREDEFINED_ENTITY: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 478 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 479 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 480 | ctxt->sax->error(ctxt->userData, |
| 481 | "Predefined entity %s without content !\n", entity->name); |
| 482 | break; |
| 483 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 484 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 485 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 486 | input = xmlNewInputStream(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 487 | if (input == NULL) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 488 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 489 | } |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 490 | input->filename = (char *) entity->SystemID; /* TODO !!! char <- xmlChar */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 491 | input->base = entity->content; |
| 492 | input->cur = entity->content; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 493 | return(input); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 496 | /** |
| 497 | * xmlNewStringInputStream: |
| 498 | * @ctxt: an XML parser context |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 499 | * @buffer: an memory buffer |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 500 | * |
| 501 | * Create a new input stream based on a memory buffer. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 502 | * Returns the new input stream |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 503 | */ |
| 504 | xmlParserInputPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 505 | xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 506 | xmlParserInputPtr input; |
| 507 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 508 | if (buffer == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 509 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 510 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 511 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 512 | "internal: xmlNewStringInputStream string = NULL\n"); |
| 513 | return(NULL); |
| 514 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 515 | input = xmlNewInputStream(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 516 | if (input == NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 517 | return(NULL); |
| 518 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 519 | input->base = buffer; |
| 520 | input->cur = buffer; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 521 | return(input); |
| 522 | } |
| 523 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 524 | /** |
| 525 | * xmlNewInputFromFile: |
| 526 | * @ctxt: an XML parser context |
| 527 | * @filename: the filename to use as entity |
| 528 | * |
| 529 | * Create a new input stream based on a file. |
| 530 | * |
| 531 | * Returns the new input stream or NULL in case of error |
| 532 | */ |
| 533 | xmlParserInputPtr |
| 534 | xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 535 | xmlParserInputBufferPtr buf; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 536 | xmlParserInputPtr inputStream; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 537 | char *directory = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 538 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 539 | if (ctxt == NULL) return(NULL); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 540 | buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 541 | if (buf == NULL) { |
| 542 | char name[1024]; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 543 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 544 | if ((ctxt->input != NULL) && (ctxt->input->directory != NULL)) { |
| 545 | #ifdef WIN32 |
| 546 | sprintf(name, "%s\\%s", ctxt->input->directory, filename); |
| 547 | #else |
| 548 | sprintf(name, "%s/%s", ctxt->input->directory, filename); |
| 549 | #endif |
| 550 | buf = xmlParserInputBufferCreateFilename(name, |
| 551 | XML_CHAR_ENCODING_NONE); |
| 552 | if (buf != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 553 | directory = xmlMemStrdup(ctxt->input->directory); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 554 | } |
| 555 | if ((buf == NULL) && (ctxt->directory != NULL)) { |
| 556 | #ifdef WIN32 |
| 557 | sprintf(name, "%s\\%s", ctxt->directory, filename); |
| 558 | #else |
| 559 | sprintf(name, "%s/%s", ctxt->directory, filename); |
| 560 | #endif |
| 561 | buf = xmlParserInputBufferCreateFilename(name, |
| 562 | XML_CHAR_ENCODING_NONE); |
| 563 | if (buf != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 564 | directory = xmlMemStrdup(ctxt->directory); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 565 | } |
| 566 | if (buf == NULL) |
| 567 | return(NULL); |
| 568 | } |
| 569 | if (directory == NULL) |
| 570 | directory = xmlParserGetDirectory(filename); |
| 571 | |
| 572 | inputStream = xmlNewInputStream(ctxt); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 573 | if (inputStream == NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 574 | if (directory != NULL) xmlFree((char *) directory); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 575 | return(NULL); |
| 576 | } |
| 577 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 578 | inputStream->filename = xmlMemStrdup(filename); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 579 | inputStream->directory = directory; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 580 | inputStream->buf = buf; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 581 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 582 | inputStream->base = inputStream->buf->buffer->content; |
| 583 | inputStream->cur = inputStream->buf->buffer->content; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 584 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 585 | ctxt->directory = directory; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 586 | return(inputStream); |
| 587 | } |
| 588 | |
| 589 | /************************************************************************ |
| 590 | * * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 591 | * Commodity functions to handle parser contexts * |
| 592 | * * |
| 593 | ************************************************************************/ |
| 594 | |
| 595 | /** |
| 596 | * xmlInitParserCtxt: |
| 597 | * @ctxt: an XML parser context |
| 598 | * |
| 599 | * Initialize a parser context |
| 600 | */ |
| 601 | |
| 602 | void |
| 603 | xmlInitParserCtxt(xmlParserCtxtPtr ctxt) |
| 604 | { |
| 605 | xmlSAXHandler *sax; |
| 606 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 607 | sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 608 | if (sax == NULL) { |
| 609 | fprintf(stderr, "xmlInitParserCtxt: out of memory\n"); |
| 610 | } |
| 611 | |
| 612 | /* Allocate the Input stack */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 613 | ctxt->inputTab = (xmlParserInputPtr *) xmlMalloc(5 * sizeof(xmlParserInputPtr)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 614 | ctxt->inputNr = 0; |
| 615 | ctxt->inputMax = 5; |
| 616 | ctxt->input = NULL; |
| 617 | ctxt->version = NULL; |
| 618 | ctxt->encoding = NULL; |
| 619 | ctxt->standalone = -1; |
| 620 | ctxt->hasExternalSubset = 0; |
| 621 | ctxt->hasPErefs = 0; |
| 622 | ctxt->html = 0; |
| 623 | ctxt->external = 0; |
| 624 | ctxt->instate = XML_PARSER_PROLOG; |
| 625 | ctxt->token = 0; |
| 626 | ctxt->directory = NULL; |
| 627 | |
| 628 | /* Allocate the Node stack */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 629 | ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 630 | ctxt->nodeNr = 0; |
| 631 | ctxt->nodeMax = 10; |
| 632 | ctxt->node = NULL; |
| 633 | |
| 634 | if (sax == NULL) ctxt->sax = &xmlDefaultSAXHandler; |
| 635 | else { |
| 636 | ctxt->sax = sax; |
| 637 | memcpy(sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler)); |
| 638 | } |
| 639 | ctxt->userData = ctxt; |
| 640 | ctxt->myDoc = NULL; |
| 641 | ctxt->wellFormed = 1; |
| 642 | ctxt->valid = 1; |
| 643 | ctxt->validate = xmlDoValidityCheckingDefaultValue; |
| 644 | ctxt->vctxt.userData = ctxt; |
| 645 | ctxt->vctxt.error = xmlParserValidityError; |
| 646 | ctxt->vctxt.warning = xmlParserValidityWarning; |
| 647 | ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue; |
| 648 | ctxt->record_info = 0; |
| 649 | xmlInitNodeInfoSeq(&ctxt->node_seq); |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * xmlFreeParserCtxt: |
| 654 | * @ctxt: an XML parser context |
| 655 | * |
| 656 | * Free all the memory used by a parser context. However the parsed |
| 657 | * document in ctxt->myDoc is not freed. |
| 658 | */ |
| 659 | |
| 660 | void |
| 661 | xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) |
| 662 | { |
| 663 | xmlParserInputPtr input; |
| 664 | |
| 665 | if (ctxt == NULL) return; |
| 666 | |
| 667 | while ((input = inputPop(ctxt)) != NULL) { |
| 668 | xmlFreeInputStream(input); |
| 669 | } |
| 670 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 671 | if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab); |
| 672 | if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab); |
| 673 | if (ctxt->version != NULL) xmlFree((char *) ctxt->version); |
| 674 | if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 675 | if ((ctxt->sax != NULL) && (ctxt->sax != &xmlDefaultSAXHandler)) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 676 | xmlFree(ctxt->sax); |
| 677 | if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory); |
| 678 | xmlFree(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /** |
| 682 | * xmlNewParserCtxt: |
| 683 | * |
| 684 | * Allocate and initialize a new parser context. |
| 685 | * |
| 686 | * Returns the xmlParserCtxtPtr or NULL |
| 687 | */ |
| 688 | |
| 689 | xmlParserCtxtPtr |
| 690 | xmlNewParserCtxt() |
| 691 | { |
| 692 | xmlParserCtxtPtr ctxt; |
| 693 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 694 | ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 695 | if (ctxt == NULL) { |
| 696 | fprintf(stderr, "xmlNewParserCtxt : cannot allocate context\n"); |
| 697 | perror("malloc"); |
| 698 | return(NULL); |
| 699 | } |
| 700 | xmlInitParserCtxt(ctxt); |
| 701 | return(ctxt); |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * xmlClearParserCtxt: |
| 706 | * @ctxt: an XML parser context |
| 707 | * |
| 708 | * Clear (release owned resources) and reinitialize a parser context |
| 709 | */ |
| 710 | |
| 711 | void |
| 712 | xmlClearParserCtxt(xmlParserCtxtPtr ctxt) |
| 713 | { |
| 714 | xmlClearNodeInfoSeq(&ctxt->node_seq); |
| 715 | xmlInitParserCtxt(ctxt); |
| 716 | } |
| 717 | |
| 718 | /************************************************************************ |
| 719 | * * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 720 | * Commodity functions to handle entities * |
| 721 | * * |
| 722 | ************************************************************************/ |
| 723 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 724 | void xmlParserHandleReference(xmlParserCtxtPtr ctxt); |
| 725 | void xmlParserHandlePEReference(xmlParserCtxtPtr ctxt); |
| 726 | |
| 727 | /** |
| 728 | * xmlParseCharRef: |
| 729 | * @ctxt: an XML parser context |
| 730 | * |
| 731 | * parse Reference declarations |
| 732 | * |
| 733 | * [66] CharRef ::= '&#' [0-9]+ ';' | |
| 734 | * '&#x' [0-9a-fA-F]+ ';' |
| 735 | * |
| 736 | * [ WFC: Legal Character ] |
| 737 | * Characters referred to using character references must match the |
| 738 | * production for Char. |
| 739 | * |
| 740 | * Returns the value parsed (as an int) |
| 741 | */ |
| 742 | int |
| 743 | xmlParseCharRef(xmlParserCtxtPtr ctxt) { |
| 744 | int val = 0; |
| 745 | |
| 746 | if (ctxt->token != 0) { |
| 747 | val = ctxt->token; |
| 748 | ctxt->token = 0; |
| 749 | return(val); |
| 750 | } |
| 751 | if ((CUR == '&') && (NXT(1) == '#') && |
| 752 | (NXT(2) == 'x')) { |
| 753 | SKIP(3); |
| 754 | while (CUR != ';') { |
| 755 | if ((CUR >= '0') && (CUR <= '9')) |
| 756 | val = val * 16 + (CUR - '0'); |
| 757 | else if ((CUR >= 'a') && (CUR <= 'f')) |
| 758 | val = val * 16 + (CUR - 'a') + 10; |
| 759 | else if ((CUR >= 'A') && (CUR <= 'F')) |
| 760 | val = val * 16 + (CUR - 'A') + 10; |
| 761 | else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 762 | ctxt->errNo = XML_ERR_INVALID_HEX_CHARREF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 763 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 764 | ctxt->sax->error(ctxt->userData, |
| 765 | "xmlParseCharRef: invalid hexadecimal value\n"); |
| 766 | ctxt->wellFormed = 0; |
| 767 | val = 0; |
| 768 | break; |
| 769 | } |
| 770 | NEXT; |
| 771 | } |
| 772 | if (CUR == ';') |
| 773 | NEXT; |
| 774 | } else if ((CUR == '&') && (NXT(1) == '#')) { |
| 775 | SKIP(2); |
| 776 | while (CUR != ';') { |
| 777 | if ((CUR >= '0') && (CUR <= '9')) |
| 778 | val = val * 10 + (CUR - '0'); |
| 779 | else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 780 | ctxt->errNo = XML_ERR_INVALID_DEC_CHARREF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 781 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 782 | ctxt->sax->error(ctxt->userData, |
| 783 | "xmlParseCharRef: invalid decimal value\n"); |
| 784 | ctxt->wellFormed = 0; |
| 785 | val = 0; |
| 786 | break; |
| 787 | } |
| 788 | NEXT; |
| 789 | } |
| 790 | if (CUR == ';') |
| 791 | NEXT; |
| 792 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 793 | ctxt->errNo = XML_ERR_INVALID_CHARREF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 794 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 795 | ctxt->sax->error(ctxt->userData, |
| 796 | "xmlParseCharRef: invalid value\n"); |
| 797 | ctxt->wellFormed = 0; |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * [ WFC: Legal Character ] |
| 802 | * Characters referred to using character references must match the |
| 803 | * production for Char. |
| 804 | */ |
| 805 | if (IS_CHAR(val)) { |
| 806 | return(val); |
| 807 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 808 | ctxt->errNo = XML_ERR_INVALID_CHAR; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 809 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 810 | ctxt->sax->error(ctxt->userData, "CharRef: invalid xmlChar value %d\n", |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 811 | val); |
| 812 | ctxt->wellFormed = 0; |
| 813 | } |
| 814 | return(0); |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * xmlParserHandleReference: |
| 819 | * @ctxt: the parser context |
| 820 | * |
| 821 | * [67] Reference ::= EntityRef | CharRef |
| 822 | * |
| 823 | * [68] EntityRef ::= '&' Name ';' |
| 824 | * |
| 825 | * [ WFC: Entity Declared ] |
| 826 | * the Name given in the entity reference must match that in an entity |
| 827 | * declaration, except that well-formed documents need not declare any |
| 828 | * of the following entities: amp, lt, gt, apos, quot. |
| 829 | * |
| 830 | * [ WFC: Parsed Entity ] |
| 831 | * An entity reference must not contain the name of an unparsed entity |
| 832 | * |
| 833 | * [66] CharRef ::= '&#' [0-9]+ ';' | |
| 834 | * '&#x' [0-9a-fA-F]+ ';' |
| 835 | * |
| 836 | * A PEReference may have been detectect in the current input stream |
| 837 | * the handling is done accordingly to |
| 838 | * http://www.w3.org/TR/REC-xml#entproc |
| 839 | */ |
| 840 | void |
| 841 | xmlParserHandleReference(xmlParserCtxtPtr ctxt) { |
| 842 | xmlParserInputPtr input; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 843 | xmlChar *name; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 844 | xmlEntityPtr ent = NULL; |
| 845 | |
| 846 | if (ctxt->token != 0) return; |
| 847 | if (CUR != '&') return; |
| 848 | GROW; |
| 849 | if ((CUR == '&') && (NXT(1) == '#')) { |
| 850 | switch(ctxt->instate) { |
| 851 | case XML_PARSER_CDATA_SECTION: |
| 852 | return; |
| 853 | case XML_PARSER_COMMENT: |
| 854 | return; |
| 855 | case XML_PARSER_EOF: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 856 | ctxt->errNo = XML_ERR_CHARREF_AT_EOF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 857 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 858 | ctxt->sax->error(ctxt->userData, "CharRef at EOF\n"); |
| 859 | ctxt->wellFormed = 0; |
| 860 | return; |
| 861 | case XML_PARSER_PROLOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 862 | ctxt->errNo = XML_ERR_CHARREF_IN_PROLOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 863 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 864 | ctxt->sax->error(ctxt->userData, "CharRef in prolog!\n"); |
| 865 | ctxt->wellFormed = 0; |
| 866 | return; |
| 867 | case XML_PARSER_EPILOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 868 | ctxt->errNo = XML_ERR_CHARREF_IN_EPILOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 869 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 870 | ctxt->sax->error(ctxt->userData, "CharRef in epilog!\n"); |
| 871 | ctxt->wellFormed = 0; |
| 872 | return; |
| 873 | case XML_PARSER_DTD: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 874 | ctxt->errNo = XML_ERR_CHARREF_IN_DTD; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 875 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 876 | ctxt->sax->error(ctxt->userData, |
| 877 | "CharRef are forbiden in DTDs!\n"); |
| 878 | ctxt->wellFormed = 0; |
| 879 | return; |
| 880 | case XML_PARSER_ENTITY_DECL: |
| 881 | /* we just ignore it there */ |
| 882 | return; |
| 883 | case XML_PARSER_ENTITY_VALUE: |
| 884 | /* |
| 885 | * NOTE: in the case of entity values, we don't do the |
| 886 | * substitution here since we need the litteral |
| 887 | * entity value to be able to save the internal |
| 888 | * subset of the document. |
| 889 | * This will be handled by xmlDecodeEntities |
| 890 | */ |
| 891 | return; |
| 892 | case XML_PARSER_CONTENT: |
| 893 | case XML_PARSER_ATTRIBUTE_VALUE: |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 894 | /* !!! this may not be Ok for UTF-8, multibyte sequence */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 895 | ctxt->token = xmlParseCharRef(ctxt); |
| 896 | return; |
| 897 | } |
| 898 | return; |
| 899 | } |
| 900 | |
| 901 | switch(ctxt->instate) { |
| 902 | case XML_PARSER_CDATA_SECTION: |
| 903 | return; |
| 904 | case XML_PARSER_COMMENT: |
| 905 | return; |
| 906 | case XML_PARSER_EOF: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 907 | ctxt->errNo = XML_ERR_ENTITYREF_AT_EOF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 908 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 909 | ctxt->sax->error(ctxt->userData, "Reference at EOF\n"); |
| 910 | ctxt->wellFormed = 0; |
| 911 | return; |
| 912 | case XML_PARSER_PROLOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 913 | ctxt->errNo = XML_ERR_ENTITYREF_IN_PROLOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 914 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 915 | ctxt->sax->error(ctxt->userData, "Reference in prolog!\n"); |
| 916 | ctxt->wellFormed = 0; |
| 917 | return; |
| 918 | case XML_PARSER_EPILOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 919 | ctxt->errNo = XML_ERR_ENTITYREF_IN_EPILOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 920 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 921 | ctxt->sax->error(ctxt->userData, "Reference in epilog!\n"); |
| 922 | ctxt->wellFormed = 0; |
| 923 | return; |
| 924 | case XML_PARSER_ENTITY_VALUE: |
| 925 | /* |
| 926 | * NOTE: in the case of entity values, we don't do the |
| 927 | * substitution here since we need the litteral |
| 928 | * entity value to be able to save the internal |
| 929 | * subset of the document. |
| 930 | * This will be handled by xmlDecodeEntities |
| 931 | */ |
| 932 | return; |
| 933 | case XML_PARSER_ATTRIBUTE_VALUE: |
| 934 | /* |
| 935 | * NOTE: in the case of attributes values, we don't do the |
| 936 | * substitution here unless we are in a mode where |
| 937 | * the parser is explicitely asked to substitute |
| 938 | * entities. The SAX callback is called with values |
| 939 | * without entity substitution. |
| 940 | * This will then be handled by xmlDecodeEntities |
| 941 | */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 942 | return; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 943 | case XML_PARSER_ENTITY_DECL: |
| 944 | /* |
| 945 | * we just ignore it there |
| 946 | * the substitution will be done once the entity is referenced |
| 947 | */ |
| 948 | return; |
| 949 | case XML_PARSER_DTD: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 950 | ctxt->errNo = XML_ERR_ENTITYREF_IN_DTD; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 951 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 952 | ctxt->sax->error(ctxt->userData, |
| 953 | "Entity references are forbiden in DTDs!\n"); |
| 954 | ctxt->wellFormed = 0; |
| 955 | return; |
| 956 | case XML_PARSER_CONTENT: |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 957 | return; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | NEXT; |
| 961 | name = xmlScanName(ctxt); |
| 962 | if (name == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 963 | ctxt->errNo = XML_ERR_ENTITYREF_NO_NAME; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 964 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 965 | ctxt->sax->error(ctxt->userData, "Entity reference: no name\n"); |
| 966 | ctxt->wellFormed = 0; |
| 967 | ctxt->token = '&'; |
| 968 | return; |
| 969 | } |
| 970 | if (NXT(xmlStrlen(name)) != ';') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 971 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 972 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 973 | ctxt->sax->error(ctxt->userData, |
| 974 | "Entity reference: ';' expected\n"); |
| 975 | ctxt->wellFormed = 0; |
| 976 | ctxt->token = '&'; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 977 | xmlFree(name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 978 | return; |
| 979 | } |
| 980 | SKIP(xmlStrlen(name) + 1); |
| 981 | if (ctxt->sax != NULL) { |
| 982 | if (ctxt->sax->getEntity != NULL) |
| 983 | ent = ctxt->sax->getEntity(ctxt->userData, name); |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * [ WFC: Entity Declared ] |
| 988 | * the Name given in the entity reference must match that in an entity |
| 989 | * declaration, except that well-formed documents need not declare any |
| 990 | * of the following entities: amp, lt, gt, apos, quot. |
| 991 | */ |
| 992 | if (ent == NULL) |
| 993 | ent = xmlGetPredefinedEntity(name); |
| 994 | if (ent == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 995 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 996 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 997 | ctxt->sax->error(ctxt->userData, |
| 998 | "Entity reference: entity %s not declared\n", |
| 999 | name); |
| 1000 | ctxt->wellFormed = 0; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1001 | xmlFree(name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | /* |
| 1006 | * [ WFC: Parsed Entity ] |
| 1007 | * An entity reference must not contain the name of an unparsed entity |
| 1008 | */ |
| 1009 | if (ent->type == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1010 | ctxt->errNo = XML_ERR_UNPARSED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1011 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1012 | ctxt->sax->error(ctxt->userData, |
| 1013 | "Entity reference to unparsed entity %s\n", name); |
| 1014 | ctxt->wellFormed = 0; |
| 1015 | } |
| 1016 | |
| 1017 | if (ent->type == XML_INTERNAL_PREDEFINED_ENTITY) { |
| 1018 | ctxt->token = ent->content[0]; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1019 | xmlFree(name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1020 | return; |
| 1021 | } |
| 1022 | input = xmlNewEntityInputStream(ctxt, ent); |
| 1023 | xmlPushInput(ctxt, input); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1024 | xmlFree(name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * xmlParserHandlePEReference: |
| 1030 | * @ctxt: the parser context |
| 1031 | * |
| 1032 | * [69] PEReference ::= '%' Name ';' |
| 1033 | * |
| 1034 | * [ WFC: No Recursion ] |
| 1035 | * TODO A parsed entity must not contain a recursive |
| 1036 | * reference to itself, either directly or indirectly. |
| 1037 | * |
| 1038 | * [ WFC: Entity Declared ] |
| 1039 | * In a document without any DTD, a document with only an internal DTD |
| 1040 | * subset which contains no parameter entity references, or a document |
| 1041 | * with "standalone='yes'", ... ... The declaration of a parameter |
| 1042 | * entity must precede any reference to it... |
| 1043 | * |
| 1044 | * [ VC: Entity Declared ] |
| 1045 | * In a document with an external subset or external parameter entities |
| 1046 | * with "standalone='no'", ... ... The declaration of a parameter entity |
| 1047 | * must precede any reference to it... |
| 1048 | * |
| 1049 | * [ WFC: In DTD ] |
| 1050 | * Parameter-entity references may only appear in the DTD. |
| 1051 | * NOTE: misleading but this is handled. |
| 1052 | * |
| 1053 | * A PEReference may have been detected in the current input stream |
| 1054 | * the handling is done accordingly to |
| 1055 | * http://www.w3.org/TR/REC-xml#entproc |
| 1056 | * i.e. |
| 1057 | * - Included in literal in entity values |
| 1058 | * - Included as Paraemeter Entity reference within DTDs |
| 1059 | */ |
| 1060 | void |
| 1061 | xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1062 | xmlChar *name; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1063 | xmlEntityPtr entity = NULL; |
| 1064 | xmlParserInputPtr input; |
| 1065 | |
| 1066 | if (ctxt->token != 0) return; |
| 1067 | if (CUR != '%') return; |
| 1068 | switch(ctxt->instate) { |
| 1069 | case XML_PARSER_CDATA_SECTION: |
| 1070 | return; |
| 1071 | case XML_PARSER_COMMENT: |
| 1072 | return; |
| 1073 | case XML_PARSER_EOF: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1074 | ctxt->errNo = XML_ERR_PEREF_AT_EOF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1075 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1076 | ctxt->sax->error(ctxt->userData, "PEReference at EOF\n"); |
| 1077 | ctxt->wellFormed = 0; |
| 1078 | return; |
| 1079 | case XML_PARSER_PROLOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1080 | ctxt->errNo = XML_ERR_PEREF_IN_PROLOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1081 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1082 | ctxt->sax->error(ctxt->userData, "PEReference in prolog!\n"); |
| 1083 | ctxt->wellFormed = 0; |
| 1084 | return; |
| 1085 | case XML_PARSER_ENTITY_DECL: |
| 1086 | case XML_PARSER_CONTENT: |
| 1087 | case XML_PARSER_ATTRIBUTE_VALUE: |
| 1088 | /* we just ignore it there */ |
| 1089 | return; |
| 1090 | case XML_PARSER_EPILOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1091 | ctxt->errNo = XML_ERR_PEREF_IN_EPILOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1092 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1093 | ctxt->sax->error(ctxt->userData, "PEReference in epilog!\n"); |
| 1094 | ctxt->wellFormed = 0; |
| 1095 | return; |
| 1096 | case XML_PARSER_ENTITY_VALUE: |
| 1097 | /* |
| 1098 | * NOTE: in the case of entity values, we don't do the |
| 1099 | * substitution here since we need the litteral |
| 1100 | * entity value to be able to save the internal |
| 1101 | * subset of the document. |
| 1102 | * This will be handled by xmlDecodeEntities |
| 1103 | */ |
| 1104 | return; |
| 1105 | case XML_PARSER_DTD: |
| 1106 | /* |
| 1107 | * [WFC: Well-Formedness Constraint: PEs in Internal Subset] |
| 1108 | * In the internal DTD subset, parameter-entity references |
| 1109 | * can occur only where markup declarations can occur, not |
| 1110 | * within markup declarations. |
| 1111 | * In that case this is handled in xmlParseMarkupDecl |
| 1112 | */ |
| 1113 | if ((ctxt->external == 0) && (ctxt->inputNr == 1)) |
| 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | NEXT; |
| 1118 | name = xmlParseName(ctxt); |
| 1119 | if (name == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1120 | ctxt->errNo = XML_ERR_PEREF_NO_NAME; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1121 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1122 | ctxt->sax->error(ctxt->userData, "xmlHandlePEReference: no name\n"); |
| 1123 | ctxt->wellFormed = 0; |
| 1124 | } else { |
| 1125 | if (CUR == ';') { |
| 1126 | NEXT; |
| 1127 | if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL)) |
| 1128 | entity = ctxt->sax->getParameterEntity(ctxt->userData, name); |
| 1129 | if (entity == NULL) { |
| 1130 | |
| 1131 | /* |
| 1132 | * [ WFC: Entity Declared ] |
| 1133 | * In a document without any DTD, a document with only an |
| 1134 | * internal DTD subset which contains no parameter entity |
| 1135 | * references, or a document with "standalone='yes'", ... |
| 1136 | * ... The declaration of a parameter entity must precede |
| 1137 | * any reference to it... |
| 1138 | */ |
| 1139 | if ((ctxt->standalone == 1) || |
| 1140 | ((ctxt->hasExternalSubset == 0) && |
| 1141 | (ctxt->hasPErefs == 0))) { |
| 1142 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1143 | ctxt->sax->error(ctxt->userData, |
| 1144 | "PEReference: %%%s; not found\n", name); |
| 1145 | ctxt->wellFormed = 0; |
| 1146 | } else { |
| 1147 | /* |
| 1148 | * [ VC: Entity Declared ] |
| 1149 | * In a document with an external subset or external |
| 1150 | * parameter entities with "standalone='no'", ... |
| 1151 | * ... The declaration of a parameter entity must precede |
| 1152 | * any reference to it... |
| 1153 | */ |
| 1154 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 1155 | ctxt->sax->warning(ctxt->userData, |
| 1156 | "PEReference: %%%s; not found\n", name); |
| 1157 | ctxt->valid = 0; |
| 1158 | } |
| 1159 | } else { |
| 1160 | if ((entity->type == XML_INTERNAL_PARAMETER_ENTITY) || |
| 1161 | (entity->type == XML_EXTERNAL_PARAMETER_ENTITY)) { |
| 1162 | /* |
| 1163 | * TODO !!!! handle the extra spaces added before and after |
| 1164 | * c.f. http://www.w3.org/TR/REC-xml#as-PE |
| 1165 | * TODO !!!! Avoid quote processing in parameters value |
| 1166 | * c.f. http://www.w3.org/TR/REC-xml#inliteral |
| 1167 | */ |
| 1168 | input = xmlNewEntityInputStream(ctxt, entity); |
| 1169 | xmlPushInput(ctxt, input); |
| 1170 | } else { |
| 1171 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1172 | ctxt->sax->error(ctxt->userData, |
| 1173 | "xmlHandlePEReference: %s is not a parameter entity\n", |
| 1174 | name); |
| 1175 | ctxt->wellFormed = 0; |
| 1176 | } |
| 1177 | } |
| 1178 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1179 | ctxt->errNo = XML_ERR_PEREF_SEMICOL_MISSING; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1180 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1181 | ctxt->sax->error(ctxt->userData, |
| 1182 | "xmlHandlePEReference: expecting ';'\n"); |
| 1183 | ctxt->wellFormed = 0; |
| 1184 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1185 | xmlFree(name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1189 | /* |
| 1190 | * Macro used to grow the current buffer. |
| 1191 | */ |
| 1192 | #define growBuffer(buffer) { \ |
| 1193 | buffer##_size *= 2; \ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1194 | buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1195 | if (buffer == NULL) { \ |
| 1196 | perror("realloc failed"); \ |
| 1197 | exit(1); \ |
| 1198 | } \ |
| 1199 | } |
| 1200 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1201 | /** |
| 1202 | * xmlDecodeEntities: |
| 1203 | * @ctxt: the parser context |
| 1204 | * @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF |
| 1205 | * @len: the len to decode (in bytes !), -1 for no size limit |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1206 | * @end: an end marker xmlChar, 0 if none |
| 1207 | * @end2: an end marker xmlChar, 0 if none |
| 1208 | * @end3: an end marker xmlChar, 0 if none |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1209 | * |
| 1210 | * [67] Reference ::= EntityRef | CharRef |
| 1211 | * |
| 1212 | * [69] PEReference ::= '%' Name ';' |
| 1213 | * |
| 1214 | * Returns A newly allocated string with the substitution done. The caller |
| 1215 | * must deallocate it ! |
| 1216 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1217 | xmlChar * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1218 | xmlDecodeEntities(xmlParserCtxtPtr ctxt, int len, int what, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1219 | xmlChar end, xmlChar end2, xmlChar end3) { |
| 1220 | xmlChar *buffer = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1221 | int buffer_size = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1222 | xmlChar *out = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1223 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1224 | xmlChar *current = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1225 | xmlEntityPtr ent; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1226 | int nbchars = 0; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1227 | unsigned int max = (unsigned int) len; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1228 | xmlChar cur; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1229 | |
| 1230 | /* |
| 1231 | * allocate a translation buffer. |
| 1232 | */ |
| 1233 | buffer_size = 1000; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1234 | buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1235 | if (buffer == NULL) { |
| 1236 | perror("xmlDecodeEntities: malloc failed"); |
| 1237 | return(NULL); |
| 1238 | } |
| 1239 | out = buffer; |
| 1240 | |
| 1241 | /* |
| 1242 | * Ok loop until we reach one of the ending char or a size limit. |
| 1243 | */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1244 | cur = CUR; |
| 1245 | while ((nbchars < max) && (cur != end) && |
| 1246 | (cur != end2) && (cur != end3)) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1247 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1248 | if (cur == 0) break; |
| 1249 | if ((cur == '&') && (NXT(1) == '#')) { |
| 1250 | int val = xmlParseCharRef(ctxt); |
| 1251 | *out++ = val; |
| 1252 | nbchars += 3; |
| 1253 | } else if ((cur == '&') && (what & XML_SUBSTITUTE_REF)) { |
| 1254 | ent = xmlParseEntityRef(ctxt); |
| 1255 | if ((ent != NULL) && |
| 1256 | (ctxt->replaceEntities != 0)) { |
| 1257 | current = ent->content; |
| 1258 | while (*current != 0) { |
| 1259 | *out++ = *current++; |
| 1260 | if (out - buffer > buffer_size - 100) { |
| 1261 | int index = out - buffer; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1262 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1263 | growBuffer(buffer); |
| 1264 | out = &buffer[index]; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1267 | nbchars += 3 + xmlStrlen(ent->name); |
| 1268 | } else if (ent != NULL) { |
| 1269 | int i = xmlStrlen(ent->name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1270 | const xmlChar *cur = ent->name; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1271 | |
| 1272 | nbchars += i + 2; |
| 1273 | *out++ = '&'; |
| 1274 | if (out - buffer > buffer_size - i - 100) { |
| 1275 | int index = out - buffer; |
| 1276 | |
| 1277 | growBuffer(buffer); |
| 1278 | out = &buffer[index]; |
| 1279 | } |
| 1280 | for (;i > 0;i--) |
| 1281 | *out++ = *cur++; |
| 1282 | *out++ = ';'; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1283 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1284 | } else if (cur == '%' && (what & XML_SUBSTITUTE_PEREF)) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1285 | /* |
| 1286 | * a PEReference induce to switch the entity flow, |
| 1287 | * we break here to flush the current set of chars |
| 1288 | * parsed if any. We will be called back later. |
| 1289 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1290 | if (nbchars != 0) break; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1291 | |
| 1292 | xmlParsePEReference(ctxt); |
| 1293 | |
| 1294 | /* |
| 1295 | * Pop-up of finished entities. |
| 1296 | */ |
| 1297 | while ((CUR == 0) && (ctxt->inputNr > 1)) |
| 1298 | xmlPopInput(ctxt); |
| 1299 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1300 | break; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1301 | } else { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1302 | /* invalid for UTF-8 , use COPY(out); !!!!!! */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1303 | *out++ = cur; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1304 | nbchars++; |
Raph Levien | 05240da | 1999-06-15 21:27:11 +0000 | [diff] [blame] | 1305 | if (out - buffer > buffer_size - 100) { |
| 1306 | int index = out - buffer; |
| 1307 | |
| 1308 | growBuffer(buffer); |
| 1309 | out = &buffer[index]; |
| 1310 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1311 | NEXT; |
| 1312 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1313 | cur = CUR; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1314 | } |
| 1315 | *out++ = 0; |
| 1316 | return(buffer); |
| 1317 | } |
| 1318 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1319 | |
| 1320 | /************************************************************************ |
| 1321 | * * |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1322 | * Commodity functions to handle encodings * |
| 1323 | * * |
| 1324 | ************************************************************************/ |
| 1325 | |
| 1326 | /** |
| 1327 | * xmlSwitchEncoding: |
| 1328 | * @ctxt: the parser context |
| 1329 | * @len: the len of @cur |
| 1330 | * |
| 1331 | * change the input functions when discovering the character encoding |
| 1332 | * of a given entity. |
| 1333 | * |
| 1334 | */ |
| 1335 | void |
| 1336 | xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) |
| 1337 | { |
| 1338 | switch (enc) { |
| 1339 | case XML_CHAR_ENCODING_ERROR: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1340 | ctxt->errNo = XML_ERR_UNKNOWN_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1341 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1342 | ctxt->sax->error(ctxt->userData, "encoding unknown\n"); |
| 1343 | ctxt->wellFormed = 0; |
| 1344 | break; |
| 1345 | case XML_CHAR_ENCODING_NONE: |
| 1346 | /* let's assume it's UTF-8 without the XML decl */ |
| 1347 | return; |
| 1348 | case XML_CHAR_ENCODING_UTF8: |
| 1349 | /* default encoding, no conversion should be needed */ |
| 1350 | return; |
| 1351 | case XML_CHAR_ENCODING_UTF16LE: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1352 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1353 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1354 | ctxt->sax->error(ctxt->userData, |
| 1355 | "char encoding UTF16 little endian not supported\n"); |
| 1356 | break; |
| 1357 | case XML_CHAR_ENCODING_UTF16BE: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1358 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1359 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1360 | ctxt->sax->error(ctxt->userData, |
| 1361 | "char encoding UTF16 big endian not supported\n"); |
| 1362 | break; |
| 1363 | case XML_CHAR_ENCODING_UCS4LE: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1364 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1365 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1366 | ctxt->sax->error(ctxt->userData, |
| 1367 | "char encoding USC4 little endian not supported\n"); |
| 1368 | break; |
| 1369 | case XML_CHAR_ENCODING_UCS4BE: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1370 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1371 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1372 | ctxt->sax->error(ctxt->userData, |
| 1373 | "char encoding USC4 big endian not supported\n"); |
| 1374 | break; |
| 1375 | case XML_CHAR_ENCODING_EBCDIC: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1376 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1377 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1378 | ctxt->sax->error(ctxt->userData, |
| 1379 | "char encoding EBCDIC not supported\n"); |
| 1380 | break; |
| 1381 | case XML_CHAR_ENCODING_UCS4_2143: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1382 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1383 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1384 | ctxt->sax->error(ctxt->userData, |
| 1385 | "char encoding UCS4 2143 not supported\n"); |
| 1386 | break; |
| 1387 | case XML_CHAR_ENCODING_UCS4_3412: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1388 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1389 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1390 | ctxt->sax->error(ctxt->userData, |
| 1391 | "char encoding UCS4 3412 not supported\n"); |
| 1392 | break; |
| 1393 | case XML_CHAR_ENCODING_UCS2: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1394 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1395 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1396 | ctxt->sax->error(ctxt->userData, |
| 1397 | "char encoding UCS2 not supported\n"); |
| 1398 | break; |
| 1399 | case XML_CHAR_ENCODING_8859_1: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1400 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1401 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1402 | ctxt->sax->error(ctxt->userData, |
| 1403 | "char encoding ISO_8859_1 ISO Latin 1 not supported\n"); |
| 1404 | break; |
| 1405 | case XML_CHAR_ENCODING_8859_2: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1406 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1407 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1408 | ctxt->sax->error(ctxt->userData, |
| 1409 | "char encoding ISO_8859_2 ISO Latin 2 not supported\n"); |
| 1410 | break; |
| 1411 | case XML_CHAR_ENCODING_8859_3: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1412 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1413 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1414 | ctxt->sax->error(ctxt->userData, |
| 1415 | "char encoding ISO_8859_3 not supported\n"); |
| 1416 | break; |
| 1417 | case XML_CHAR_ENCODING_8859_4: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1418 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1419 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1420 | ctxt->sax->error(ctxt->userData, |
| 1421 | "char encoding ISO_8859_4 not supported\n"); |
| 1422 | break; |
| 1423 | case XML_CHAR_ENCODING_8859_5: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1424 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1425 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1426 | ctxt->sax->error(ctxt->userData, |
| 1427 | "char encoding ISO_8859_5 not supported\n"); |
| 1428 | break; |
| 1429 | case XML_CHAR_ENCODING_8859_6: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1430 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1431 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1432 | ctxt->sax->error(ctxt->userData, |
| 1433 | "char encoding ISO_8859_6 not supported\n"); |
| 1434 | break; |
| 1435 | case XML_CHAR_ENCODING_8859_7: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1436 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1437 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1438 | ctxt->sax->error(ctxt->userData, |
| 1439 | "char encoding ISO_8859_7 not supported\n"); |
| 1440 | break; |
| 1441 | case XML_CHAR_ENCODING_8859_8: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1442 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1443 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1444 | ctxt->sax->error(ctxt->userData, |
| 1445 | "char encoding ISO_8859_8 not supported\n"); |
| 1446 | break; |
| 1447 | case XML_CHAR_ENCODING_8859_9: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1448 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1449 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1450 | ctxt->sax->error(ctxt->userData, |
| 1451 | "char encoding ISO_8859_9 not supported\n"); |
| 1452 | break; |
| 1453 | case XML_CHAR_ENCODING_2022_JP: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1454 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1455 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1456 | ctxt->sax->error(ctxt->userData, |
| 1457 | "char encoding ISO-2022-JPnot supported\n"); |
| 1458 | break; |
| 1459 | case XML_CHAR_ENCODING_SHIFT_JIS: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1460 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1461 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1462 | ctxt->sax->error(ctxt->userData, |
| 1463 | "char encoding Shift_JISnot supported\n"); |
| 1464 | break; |
| 1465 | case XML_CHAR_ENCODING_EUC_JP: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1466 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1467 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1468 | ctxt->sax->error(ctxt->userData, |
| 1469 | "char encoding EUC-JPnot supported\n"); |
| 1470 | break; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | /************************************************************************ |
| 1475 | * * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1476 | * Commodity functions to handle xmlChars * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1477 | * * |
| 1478 | ************************************************************************/ |
| 1479 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1480 | /** |
| 1481 | * xmlStrndup: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1482 | * @cur: the input xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1483 | * @len: the len of @cur |
| 1484 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1485 | * a strndup for array of xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1486 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1487 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1488 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1489 | xmlChar * |
| 1490 | xmlStrndup(const xmlChar *cur, int len) { |
| 1491 | xmlChar *ret = xmlMalloc((len + 1) * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1492 | |
| 1493 | if (ret == NULL) { |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1494 | fprintf(stderr, "malloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1495 | (len + 1) * (long)sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1496 | return(NULL); |
| 1497 | } |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1498 | memcpy(ret, cur, len * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1499 | ret[len] = 0; |
| 1500 | return(ret); |
| 1501 | } |
| 1502 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1503 | /** |
| 1504 | * xmlStrdup: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1505 | * @cur: the input xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1506 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1507 | * a strdup for array of xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1508 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1509 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1510 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1511 | xmlChar * |
| 1512 | xmlStrdup(const xmlChar *cur) { |
| 1513 | const xmlChar *p = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1514 | |
| 1515 | while (IS_CHAR(*p)) p++; |
| 1516 | return(xmlStrndup(cur, p - cur)); |
| 1517 | } |
| 1518 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1519 | /** |
| 1520 | * xmlCharStrndup: |
| 1521 | * @cur: the input char * |
| 1522 | * @len: the len of @cur |
| 1523 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1524 | * a strndup for char's to xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1525 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1526 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1527 | */ |
| 1528 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1529 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1530 | xmlCharStrndup(const char *cur, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1531 | int i; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1532 | xmlChar *ret = xmlMalloc((len + 1) * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1533 | |
| 1534 | if (ret == NULL) { |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1535 | fprintf(stderr, "malloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1536 | (len + 1) * (long)sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1537 | return(NULL); |
| 1538 | } |
| 1539 | for (i = 0;i < len;i++) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1540 | ret[i] = (xmlChar) cur[i]; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1541 | ret[len] = 0; |
| 1542 | return(ret); |
| 1543 | } |
| 1544 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1545 | /** |
| 1546 | * xmlCharStrdup: |
| 1547 | * @cur: the input char * |
| 1548 | * @len: the len of @cur |
| 1549 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1550 | * a strdup for char's to xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1551 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1552 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1553 | */ |
| 1554 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1555 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1556 | xmlCharStrdup(const char *cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1557 | const char *p = cur; |
| 1558 | |
| 1559 | while (*p != '\0') p++; |
| 1560 | return(xmlCharStrndup(cur, p - cur)); |
| 1561 | } |
| 1562 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1563 | /** |
| 1564 | * xmlStrcmp: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1565 | * @str1: the first xmlChar * |
| 1566 | * @str2: the second xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1567 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1568 | * a strcmp for xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1569 | * |
| 1570 | * Returns the integer result of the comparison |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1571 | */ |
| 1572 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1573 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1574 | xmlStrcmp(const xmlChar *str1, const xmlChar *str2) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1575 | register int tmp; |
| 1576 | |
| 1577 | do { |
| 1578 | tmp = *str1++ - *str2++; |
| 1579 | if (tmp != 0) return(tmp); |
| 1580 | } while ((*str1 != 0) && (*str2 != 0)); |
| 1581 | return (*str1 - *str2); |
| 1582 | } |
| 1583 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1584 | /** |
| 1585 | * xmlStrncmp: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1586 | * @str1: the first xmlChar * |
| 1587 | * @str2: the second xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1588 | * @len: the max comparison length |
| 1589 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1590 | * a strncmp for xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1591 | * |
| 1592 | * Returns the integer result of the comparison |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1593 | */ |
| 1594 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1595 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1596 | xmlStrncmp(const xmlChar *str1, const xmlChar *str2, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1597 | register int tmp; |
| 1598 | |
| 1599 | if (len <= 0) return(0); |
| 1600 | do { |
| 1601 | tmp = *str1++ - *str2++; |
| 1602 | if (tmp != 0) return(tmp); |
| 1603 | len--; |
| 1604 | if (len <= 0) return(0); |
| 1605 | } while ((*str1 != 0) && (*str2 != 0)); |
| 1606 | return (*str1 - *str2); |
| 1607 | } |
| 1608 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1609 | /** |
| 1610 | * xmlStrchr: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1611 | * @str: the xmlChar * array |
| 1612 | * @val: the xmlChar to search |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1613 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1614 | * a strchr for xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1615 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1616 | * Returns the xmlChar * for the first occurence or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1617 | */ |
| 1618 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1619 | const xmlChar * |
| 1620 | xmlStrchr(const xmlChar *str, xmlChar val) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1621 | while (*str != 0) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1622 | if (*str == val) return((xmlChar *) str); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1623 | str++; |
| 1624 | } |
| 1625 | return(NULL); |
| 1626 | } |
| 1627 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1628 | /** |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1629 | * xmlStrstr: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1630 | * @str: the xmlChar * array (haystack) |
| 1631 | * @val: the xmlChar to search (needle) |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1632 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1633 | * a strstr for xmlChar's |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1634 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1635 | * Returns the xmlChar * for the first occurence or NULL. |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1636 | */ |
| 1637 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1638 | const xmlChar * |
| 1639 | xmlStrstr(const xmlChar *str, xmlChar *val) { |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1640 | int n; |
| 1641 | |
| 1642 | if (str == NULL) return(NULL); |
| 1643 | if (val == NULL) return(NULL); |
| 1644 | n = xmlStrlen(val); |
| 1645 | |
| 1646 | if (n == 0) return(str); |
| 1647 | while (*str != 0) { |
| 1648 | if (*str == *val) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1649 | if (!xmlStrncmp(str, val, n)) return((const xmlChar *) str); |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1650 | } |
| 1651 | str++; |
| 1652 | } |
| 1653 | return(NULL); |
| 1654 | } |
| 1655 | |
| 1656 | /** |
| 1657 | * xmlStrsub: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1658 | * @str: the xmlChar * array (haystack) |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1659 | * @start: the index of the first char (zero based) |
| 1660 | * @len: the length of the substring |
| 1661 | * |
| 1662 | * Extract a substring of a given string |
| 1663 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1664 | * Returns the xmlChar * for the first occurence or NULL. |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1665 | */ |
| 1666 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1667 | xmlChar * |
| 1668 | xmlStrsub(const xmlChar *str, int start, int len) { |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1669 | int i; |
| 1670 | |
| 1671 | if (str == NULL) return(NULL); |
| 1672 | if (start < 0) return(NULL); |
| 1673 | if (len < 0) return(NULL); |
| 1674 | |
| 1675 | for (i = 0;i < start;i++) { |
| 1676 | if (*str == 0) return(NULL); |
| 1677 | str++; |
| 1678 | } |
| 1679 | if (*str == 0) return(NULL); |
| 1680 | return(xmlStrndup(str, len)); |
| 1681 | } |
| 1682 | |
| 1683 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1684 | * xmlStrlen: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1685 | * @str: the xmlChar * array |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1686 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1687 | * lenght of a xmlChar's string |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1688 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1689 | * Returns the number of xmlChar contained in the ARRAY. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1690 | */ |
| 1691 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1692 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1693 | xmlStrlen(const xmlChar *str) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1694 | int len = 0; |
| 1695 | |
| 1696 | if (str == NULL) return(0); |
| 1697 | while (*str != 0) { |
| 1698 | str++; |
| 1699 | len++; |
| 1700 | } |
| 1701 | return(len); |
| 1702 | } |
| 1703 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1704 | /** |
| 1705 | * xmlStrncat: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1706 | * @cur: the original xmlChar * array |
| 1707 | * @add: the xmlChar * array added |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1708 | * @len: the length of @add |
| 1709 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1710 | * a strncat for array of xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1711 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1712 | * Returns a new xmlChar * containing the concatenated string. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1713 | */ |
| 1714 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1715 | xmlChar * |
| 1716 | xmlStrncat(xmlChar *cur, const xmlChar *add, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1717 | int size; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1718 | xmlChar *ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1719 | |
| 1720 | if ((add == NULL) || (len == 0)) |
| 1721 | return(cur); |
| 1722 | if (cur == NULL) |
| 1723 | return(xmlStrndup(add, len)); |
| 1724 | |
| 1725 | size = xmlStrlen(cur); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1726 | ret = xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1727 | if (ret == NULL) { |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1728 | fprintf(stderr, "xmlStrncat: realloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1729 | (size + len + 1) * (long)sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1730 | return(cur); |
| 1731 | } |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1732 | memcpy(&ret[size], add, len * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1733 | ret[size + len] = 0; |
| 1734 | return(ret); |
| 1735 | } |
| 1736 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1737 | /** |
| 1738 | * xmlStrcat: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1739 | * @cur: the original xmlChar * array |
| 1740 | * @add: the xmlChar * array added |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1741 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1742 | * a strcat for array of xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1743 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1744 | * Returns a new xmlChar * containing the concatenated string. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1745 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1746 | xmlChar * |
| 1747 | xmlStrcat(xmlChar *cur, const xmlChar *add) { |
| 1748 | const xmlChar *p = add; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1749 | |
| 1750 | if (add == NULL) return(cur); |
| 1751 | if (cur == NULL) |
| 1752 | return(xmlStrdup(add)); |
| 1753 | |
| 1754 | while (IS_CHAR(*p)) p++; |
| 1755 | return(xmlStrncat(cur, add, p - add)); |
| 1756 | } |
| 1757 | |
| 1758 | /************************************************************************ |
| 1759 | * * |
| 1760 | * Commodity functions, cleanup needed ? * |
| 1761 | * * |
| 1762 | ************************************************************************/ |
| 1763 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1764 | /** |
| 1765 | * areBlanks: |
| 1766 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1767 | * @str: a xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1768 | * @len: the size of @str |
| 1769 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1770 | * Is this a sequence of blank chars that one can ignore ? |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1771 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1772 | * TODO: Whether white space are significant has to be checked accordingly |
| 1773 | * to DTD informations if available |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1774 | * |
| 1775 | * Returns 1 if ignorable 0 otherwise. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1776 | */ |
| 1777 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1778 | static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1779 | int i, ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1780 | xmlNodePtr lastChild; |
| 1781 | |
| 1782 | for (i = 0;i < len;i++) |
| 1783 | if (!(IS_BLANK(str[i]))) return(0); |
| 1784 | |
| 1785 | if (CUR != '<') return(0); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1786 | if (ctxt->node == NULL) return(0); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1787 | if (ctxt->myDoc != NULL) { |
| 1788 | ret = xmlIsMixedElement(ctxt->myDoc, ctxt->node->name); |
| 1789 | if (ret == 0) return(1); |
| 1790 | if (ret == 1) return(0); |
| 1791 | } |
| 1792 | /* |
| 1793 | * heuristic |
| 1794 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1795 | lastChild = xmlGetLastChild(ctxt->node); |
| 1796 | if (lastChild == NULL) { |
| 1797 | if (ctxt->node->content != NULL) return(0); |
| 1798 | } else if (xmlNodeIsText(lastChild)) |
| 1799 | return(0); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1800 | else if ((ctxt->node->childs != NULL) && |
| 1801 | (xmlNodeIsText(ctxt->node->childs))) |
| 1802 | return(0); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1803 | return(1); |
| 1804 | } |
| 1805 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1806 | /** |
| 1807 | * xmlHandleEntity: |
| 1808 | * @ctxt: an XML parser context |
| 1809 | * @entity: an XML entity pointer. |
| 1810 | * |
| 1811 | * Default handling of defined entities, when should we define a new input |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1812 | * stream ? When do we just handle that as a set of chars ? |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1813 | * |
| 1814 | * OBSOLETE: to be removed at some point. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1815 | */ |
| 1816 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1817 | void |
| 1818 | xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1819 | int len; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1820 | xmlParserInputPtr input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1821 | |
| 1822 | if (entity->content == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1823 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 1824 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1825 | ctxt->sax->error(ctxt->userData, "xmlHandleEntity %s: content == NULL\n", |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1826 | entity->name); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1827 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1828 | return; |
| 1829 | } |
| 1830 | len = xmlStrlen(entity->content); |
| 1831 | if (len <= 2) goto handle_as_char; |
| 1832 | |
| 1833 | /* |
| 1834 | * Redefine its content as an input stream. |
| 1835 | */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1836 | input = xmlNewEntityInputStream(ctxt, entity); |
| 1837 | xmlPushInput(ctxt, input); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1838 | return; |
| 1839 | |
| 1840 | handle_as_char: |
| 1841 | /* |
| 1842 | * Just handle the content as a set of chars. |
| 1843 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1844 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1845 | ctxt->sax->characters(ctxt->userData, entity->content, len); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1846 | |
| 1847 | } |
| 1848 | |
| 1849 | /* |
| 1850 | * Forward definition for recusive behaviour. |
| 1851 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1852 | void xmlParsePEReference(xmlParserCtxtPtr ctxt); |
| 1853 | void xmlParseReference(xmlParserCtxtPtr ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1854 | |
| 1855 | /************************************************************************ |
| 1856 | * * |
| 1857 | * Extra stuff for namespace support * |
| 1858 | * Relates to http://www.w3.org/TR/WD-xml-names * |
| 1859 | * * |
| 1860 | ************************************************************************/ |
| 1861 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1862 | /** |
| 1863 | * xmlNamespaceParseNCName: |
| 1864 | * @ctxt: an XML parser context |
| 1865 | * |
| 1866 | * parse an XML namespace name. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1867 | * |
| 1868 | * [NS 3] NCName ::= (Letter | '_') (NCNameChar)* |
| 1869 | * |
| 1870 | * [NS 4] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | |
| 1871 | * CombiningChar | Extender |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1872 | * |
| 1873 | * Returns the namespace name or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1874 | */ |
| 1875 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1876 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1877 | xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1878 | xmlChar buf[XML_MAX_NAMELEN]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1879 | int len = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1880 | |
| 1881 | if (!IS_LETTER(CUR) && (CUR != '_')) return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1882 | |
| 1883 | while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || |
| 1884 | (CUR == '.') || (CUR == '-') || |
| 1885 | (CUR == '_') || |
| 1886 | (IS_COMBINING(CUR)) || |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1887 | (IS_EXTENDER(CUR))) { |
| 1888 | buf[len++] = CUR; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1889 | NEXT; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1890 | if (len >= XML_MAX_NAMELEN) { |
| 1891 | fprintf(stderr, |
| 1892 | "xmlNamespaceParseNCName: reached XML_MAX_NAMELEN limit\n"); |
| 1893 | while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || |
| 1894 | (CUR == '.') || (CUR == '-') || |
| 1895 | (CUR == '_') || |
| 1896 | (IS_COMBINING(CUR)) || |
| 1897 | (IS_EXTENDER(CUR))) |
| 1898 | NEXT; |
| 1899 | break; |
| 1900 | } |
| 1901 | } |
| 1902 | return(xmlStrndup(buf, len)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1905 | /** |
| 1906 | * xmlNamespaceParseQName: |
| 1907 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1908 | * @prefix: a xmlChar ** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1909 | * |
| 1910 | * parse an XML qualified name |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1911 | * |
| 1912 | * [NS 5] QName ::= (Prefix ':')? LocalPart |
| 1913 | * |
| 1914 | * [NS 6] Prefix ::= NCName |
| 1915 | * |
| 1916 | * [NS 7] LocalPart ::= NCName |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1917 | * |
| 1918 | * Returns the function returns the local part, and prefix is updated |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1919 | * to get the Prefix if any. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1920 | */ |
| 1921 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1922 | xmlChar * |
| 1923 | xmlNamespaceParseQName(xmlParserCtxtPtr ctxt, xmlChar **prefix) { |
| 1924 | xmlChar *ret = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1925 | |
| 1926 | *prefix = NULL; |
| 1927 | ret = xmlNamespaceParseNCName(ctxt); |
| 1928 | if (CUR == ':') { |
| 1929 | *prefix = ret; |
| 1930 | NEXT; |
| 1931 | ret = xmlNamespaceParseNCName(ctxt); |
| 1932 | } |
| 1933 | |
| 1934 | return(ret); |
| 1935 | } |
| 1936 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1937 | /** |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1938 | * xmlSplitQName: |
| 1939 | * @name: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1940 | * @prefix: a xmlChar ** |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1941 | * |
| 1942 | * parse an XML qualified name string |
| 1943 | * |
| 1944 | * [NS 5] QName ::= (Prefix ':')? LocalPart |
| 1945 | * |
| 1946 | * [NS 6] Prefix ::= NCName |
| 1947 | * |
| 1948 | * [NS 7] LocalPart ::= NCName |
| 1949 | * |
| 1950 | * Returns the function returns the local part, and prefix is updated |
| 1951 | * to get the Prefix if any. |
| 1952 | */ |
| 1953 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1954 | xmlChar * |
| 1955 | xmlSplitQName(const xmlChar *name, xmlChar **prefix) { |
| 1956 | xmlChar *ret = NULL; |
| 1957 | const xmlChar *q; |
| 1958 | const xmlChar *cur = name; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1959 | |
| 1960 | *prefix = NULL; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1961 | |
| 1962 | /* xml: prefix is not really a namespace */ |
| 1963 | if ((cur[0] == 'x') && (cur[1] == 'm') && |
| 1964 | (cur[2] == 'l') && (cur[3] == ':')) |
| 1965 | return(xmlStrdup(name)); |
| 1966 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1967 | if (!IS_LETTER(*cur) && (*cur != '_')) return(NULL); |
| 1968 | q = cur++; |
| 1969 | |
| 1970 | while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || |
| 1971 | (*cur == '.') || (*cur == '-') || |
| 1972 | (*cur == '_') || |
| 1973 | (IS_COMBINING(*cur)) || |
| 1974 | (IS_EXTENDER(*cur))) |
| 1975 | cur++; |
| 1976 | |
| 1977 | ret = xmlStrndup(q, cur - q); |
| 1978 | |
| 1979 | if (*cur == ':') { |
| 1980 | cur++; |
| 1981 | if (!IS_LETTER(*cur) && (*cur != '_')) return(ret); |
| 1982 | *prefix = ret; |
| 1983 | |
| 1984 | q = cur++; |
| 1985 | |
| 1986 | while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || |
| 1987 | (*cur == '.') || (*cur == '-') || |
| 1988 | (*cur == '_') || |
| 1989 | (IS_COMBINING(*cur)) || |
| 1990 | (IS_EXTENDER(*cur))) |
| 1991 | cur++; |
| 1992 | |
| 1993 | ret = xmlStrndup(q, cur - q); |
| 1994 | } |
| 1995 | |
| 1996 | return(ret); |
| 1997 | } |
| 1998 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1999 | * xmlNamespaceParseNSDef: |
| 2000 | * @ctxt: an XML parser context |
| 2001 | * |
| 2002 | * parse a namespace prefix declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2003 | * |
| 2004 | * [NS 1] NSDef ::= PrefixDef Eq SystemLiteral |
| 2005 | * |
| 2006 | * [NS 2] PrefixDef ::= 'xmlns' (':' NCName)? |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2007 | * |
| 2008 | * Returns the namespace name |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2009 | */ |
| 2010 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2011 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2012 | xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2013 | xmlChar *name = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2014 | |
| 2015 | if ((CUR == 'x') && (NXT(1) == 'm') && |
| 2016 | (NXT(2) == 'l') && (NXT(3) == 'n') && |
| 2017 | (NXT(4) == 's')) { |
| 2018 | SKIP(5); |
| 2019 | if (CUR == ':') { |
| 2020 | NEXT; |
| 2021 | name = xmlNamespaceParseNCName(ctxt); |
| 2022 | } |
| 2023 | } |
| 2024 | return(name); |
| 2025 | } |
| 2026 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2027 | /** |
| 2028 | * xmlParseQuotedString: |
| 2029 | * @ctxt: an XML parser context |
| 2030 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2031 | * [OLD] Parse and return a string between quotes or doublequotes |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2032 | * To be removed at next drop of binary compatibility |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2033 | * |
| 2034 | * Returns the string parser or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2035 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2036 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2037 | xmlParseQuotedString(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2038 | xmlChar *ret = NULL; |
| 2039 | const xmlChar *q; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2040 | |
| 2041 | if (CUR == '"') { |
| 2042 | NEXT; |
| 2043 | q = CUR_PTR; |
| 2044 | while (IS_CHAR(CUR) && (CUR != '"')) NEXT; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2045 | if (CUR != '"') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2046 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2047 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2048 | ctxt->sax->error(ctxt->userData, "String not closed \"%.50s\"\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2049 | ctxt->wellFormed = 0; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2050 | } else { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2051 | ret = xmlStrndup(q, CUR_PTR - q); |
| 2052 | NEXT; |
| 2053 | } |
| 2054 | } else if (CUR == '\''){ |
| 2055 | NEXT; |
| 2056 | q = CUR_PTR; |
| 2057 | while (IS_CHAR(CUR) && (CUR != '\'')) NEXT; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2058 | if (CUR != '\'') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2059 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2060 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2061 | ctxt->sax->error(ctxt->userData, "String not closed \"%.50s\"\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2062 | ctxt->wellFormed = 0; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2063 | } else { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2064 | ret = xmlStrndup(q, CUR_PTR - q); |
| 2065 | NEXT; |
| 2066 | } |
| 2067 | } |
| 2068 | return(ret); |
| 2069 | } |
| 2070 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2071 | /** |
| 2072 | * xmlParseNamespace: |
| 2073 | * @ctxt: an XML parser context |
| 2074 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2075 | * [OLD] xmlParseNamespace: parse specific PI '<?namespace ...' constructs. |
| 2076 | * |
| 2077 | * This is what the older xml-name Working Draft specified, a bunch of |
| 2078 | * other stuff may still rely on it, so support is still here as |
| 2079 | * if ot was declared on the root of the Tree:-( |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2080 | * |
| 2081 | * To be removed at next drop of binary compatibility |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2082 | */ |
| 2083 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2084 | void |
| 2085 | xmlParseNamespace(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2086 | xmlChar *href = NULL; |
| 2087 | xmlChar *prefix = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2088 | int garbage = 0; |
| 2089 | |
| 2090 | /* |
| 2091 | * We just skipped "namespace" or "xml:namespace" |
| 2092 | */ |
| 2093 | SKIP_BLANKS; |
| 2094 | |
| 2095 | while (IS_CHAR(CUR) && (CUR != '>')) { |
| 2096 | /* |
| 2097 | * We can have "ns" or "prefix" attributes |
| 2098 | * Old encoding as 'href' or 'AS' attributes is still supported |
| 2099 | */ |
| 2100 | if ((CUR == 'n') && (NXT(1) == 's')) { |
| 2101 | garbage = 0; |
| 2102 | SKIP(2); |
| 2103 | SKIP_BLANKS; |
| 2104 | |
| 2105 | if (CUR != '=') continue; |
| 2106 | NEXT; |
| 2107 | SKIP_BLANKS; |
| 2108 | |
| 2109 | href = xmlParseQuotedString(ctxt); |
| 2110 | SKIP_BLANKS; |
| 2111 | } else if ((CUR == 'h') && (NXT(1) == 'r') && |
| 2112 | (NXT(2) == 'e') && (NXT(3) == 'f')) { |
| 2113 | garbage = 0; |
| 2114 | SKIP(4); |
| 2115 | SKIP_BLANKS; |
| 2116 | |
| 2117 | if (CUR != '=') continue; |
| 2118 | NEXT; |
| 2119 | SKIP_BLANKS; |
| 2120 | |
| 2121 | href = xmlParseQuotedString(ctxt); |
| 2122 | SKIP_BLANKS; |
| 2123 | } else if ((CUR == 'p') && (NXT(1) == 'r') && |
| 2124 | (NXT(2) == 'e') && (NXT(3) == 'f') && |
| 2125 | (NXT(4) == 'i') && (NXT(5) == 'x')) { |
| 2126 | garbage = 0; |
| 2127 | SKIP(6); |
| 2128 | SKIP_BLANKS; |
| 2129 | |
| 2130 | if (CUR != '=') continue; |
| 2131 | NEXT; |
| 2132 | SKIP_BLANKS; |
| 2133 | |
| 2134 | prefix = xmlParseQuotedString(ctxt); |
| 2135 | SKIP_BLANKS; |
| 2136 | } else if ((CUR == 'A') && (NXT(1) == 'S')) { |
| 2137 | garbage = 0; |
| 2138 | SKIP(2); |
| 2139 | SKIP_BLANKS; |
| 2140 | |
| 2141 | if (CUR != '=') continue; |
| 2142 | NEXT; |
| 2143 | SKIP_BLANKS; |
| 2144 | |
| 2145 | prefix = xmlParseQuotedString(ctxt); |
| 2146 | SKIP_BLANKS; |
| 2147 | } else if ((CUR == '?') && (NXT(1) == '>')) { |
| 2148 | garbage = 0; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2149 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2150 | } else { |
| 2151 | /* |
| 2152 | * Found garbage when parsing the namespace |
| 2153 | */ |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2154 | if (!garbage) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2155 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2156 | ctxt->sax->error(ctxt->userData, |
| 2157 | "xmlParseNamespace found garbage\n"); |
| 2158 | } |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2159 | ctxt->errNo = XML_ERR_NS_DECL_ERROR; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2160 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2161 | NEXT; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | MOVETO_ENDTAG(CUR_PTR); |
| 2166 | NEXT; |
| 2167 | |
| 2168 | /* |
| 2169 | * Register the DTD. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2170 | if (href != NULL) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2171 | if ((ctxt->sax != NULL) && (ctxt->sax->globalNamespace != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2172 | ctxt->sax->globalNamespace(ctxt->userData, href, prefix); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2173 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2174 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2175 | if (prefix != NULL) xmlFree(prefix); |
| 2176 | if (href != NULL) xmlFree(href); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | /************************************************************************ |
| 2180 | * * |
| 2181 | * The parser itself * |
| 2182 | * Relates to http://www.w3.org/TR/REC-xml * |
| 2183 | * * |
| 2184 | ************************************************************************/ |
| 2185 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2186 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2187 | * xmlScanName: |
| 2188 | * @ctxt: an XML parser context |
| 2189 | * |
| 2190 | * Trickery: parse an XML name but without consuming the input flow |
| 2191 | * Needed for rollback cases. |
| 2192 | * |
| 2193 | * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | |
| 2194 | * CombiningChar | Extender |
| 2195 | * |
| 2196 | * [5] Name ::= (Letter | '_' | ':') (NameChar)* |
| 2197 | * |
| 2198 | * [6] Names ::= Name (S Name)* |
| 2199 | * |
| 2200 | * Returns the Name parsed or NULL |
| 2201 | */ |
| 2202 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2203 | xmlChar * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2204 | xmlScanName(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2205 | xmlChar buf[XML_MAX_NAMELEN]; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2206 | int len = 0; |
| 2207 | |
| 2208 | GROW; |
| 2209 | if (!IS_LETTER(CUR) && (CUR != '_') && |
| 2210 | (CUR != ':')) { |
| 2211 | return(NULL); |
| 2212 | } |
| 2213 | |
| 2214 | while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) || |
| 2215 | (NXT(len) == '.') || (NXT(len) == '-') || |
| 2216 | (NXT(len) == '_') || (NXT(len) == ':') || |
| 2217 | (IS_COMBINING(NXT(len))) || |
| 2218 | (IS_EXTENDER(NXT(len)))) { |
| 2219 | buf[len] = NXT(len); |
| 2220 | len++; |
| 2221 | if (len >= XML_MAX_NAMELEN) { |
| 2222 | fprintf(stderr, |
| 2223 | "xmlScanName: reached XML_MAX_NAMELEN limit\n"); |
| 2224 | while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) || |
| 2225 | (NXT(len) == '.') || (NXT(len) == '-') || |
| 2226 | (NXT(len) == '_') || (NXT(len) == ':') || |
| 2227 | (IS_COMBINING(NXT(len))) || |
| 2228 | (IS_EXTENDER(NXT(len)))) |
| 2229 | len++; |
| 2230 | break; |
| 2231 | } |
| 2232 | } |
| 2233 | return(xmlStrndup(buf, len)); |
| 2234 | } |
| 2235 | |
| 2236 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2237 | * xmlParseName: |
| 2238 | * @ctxt: an XML parser context |
| 2239 | * |
| 2240 | * parse an XML name. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2241 | * |
| 2242 | * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | |
| 2243 | * CombiningChar | Extender |
| 2244 | * |
| 2245 | * [5] Name ::= (Letter | '_' | ':') (NameChar)* |
| 2246 | * |
| 2247 | * [6] Names ::= Name (S Name)* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2248 | * |
| 2249 | * Returns the Name parsed or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2250 | */ |
| 2251 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2252 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2253 | xmlParseName(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2254 | xmlChar buf[XML_MAX_NAMELEN]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2255 | int len = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2256 | xmlChar cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2257 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2258 | GROW; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2259 | cur = CUR; |
| 2260 | if (!IS_LETTER(cur) && (cur != '_') && |
| 2261 | (cur != ':')) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2262 | return(NULL); |
| 2263 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2264 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2265 | while ((IS_LETTER(cur)) || (IS_DIGIT(cur)) || |
| 2266 | (cur == '.') || (cur == '-') || |
| 2267 | (cur == '_') || (cur == ':') || |
| 2268 | (IS_COMBINING(cur)) || |
| 2269 | (IS_EXTENDER(cur))) { |
| 2270 | buf[len++] = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2271 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2272 | cur = CUR; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2273 | if (len >= XML_MAX_NAMELEN) { |
| 2274 | fprintf(stderr, |
| 2275 | "xmlParseName: reached XML_MAX_NAMELEN limit\n"); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2276 | while ((IS_LETTER(cur)) || (IS_DIGIT(cur)) || |
| 2277 | (cur == '.') || (cur == '-') || |
| 2278 | (cur == '_') || (cur == ':') || |
| 2279 | (IS_COMBINING(cur)) || |
| 2280 | (IS_EXTENDER(cur))) { |
| 2281 | NEXT; |
| 2282 | cur = CUR; |
| 2283 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | } |
| 2286 | } |
| 2287 | return(xmlStrndup(buf, len)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2290 | /** |
| 2291 | * xmlParseNmtoken: |
| 2292 | * @ctxt: an XML parser context |
| 2293 | * |
| 2294 | * parse an XML Nmtoken. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2295 | * |
| 2296 | * [7] Nmtoken ::= (NameChar)+ |
| 2297 | * |
| 2298 | * [8] Nmtokens ::= Nmtoken (S Nmtoken)* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2299 | * |
| 2300 | * Returns the Nmtoken parsed or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2301 | */ |
| 2302 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2303 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2304 | xmlParseNmtoken(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2305 | xmlChar buf[XML_MAX_NAMELEN]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2306 | int len = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2307 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2308 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2309 | while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || |
| 2310 | (CUR == '.') || (CUR == '-') || |
| 2311 | (CUR == '_') || (CUR == ':') || |
| 2312 | (IS_COMBINING(CUR)) || |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2313 | (IS_EXTENDER(CUR))) { |
| 2314 | buf[len++] = CUR; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2315 | NEXT; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2316 | if (len >= XML_MAX_NAMELEN) { |
| 2317 | fprintf(stderr, |
| 2318 | "xmlParseNmtoken: reached XML_MAX_NAMELEN limit\n"); |
| 2319 | while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || |
| 2320 | (CUR == '.') || (CUR == '-') || |
| 2321 | (CUR == '_') || (CUR == ':') || |
| 2322 | (IS_COMBINING(CUR)) || |
| 2323 | (IS_EXTENDER(CUR))) |
| 2324 | NEXT; |
| 2325 | break; |
| 2326 | } |
| 2327 | } |
| 2328 | return(xmlStrndup(buf, len)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2331 | /** |
| 2332 | * xmlParseEntityValue: |
| 2333 | * @ctxt: an XML parser context |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2334 | * @orig: if non-NULL store a copy of the original entity value |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2335 | * |
| 2336 | * parse a value for ENTITY decl. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2337 | * |
| 2338 | * [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | |
| 2339 | * "'" ([^%&'] | PEReference | Reference)* "'" |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2340 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2341 | * Returns the EntityValue parsed with reference substitued or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2342 | */ |
| 2343 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2344 | xmlChar * |
| 2345 | xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { |
| 2346 | xmlChar *ret = NULL; |
| 2347 | const xmlChar *org = NULL; |
| 2348 | const xmlChar *tst = NULL; |
| 2349 | const xmlChar *temp = NULL; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2350 | xmlParserInputPtr input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2351 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2352 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2353 | if (CUR == '"') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2354 | ctxt->instate = XML_PARSER_ENTITY_VALUE; |
| 2355 | input = ctxt->input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2356 | NEXT; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2357 | org = CUR_PTR; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2358 | /* |
| 2359 | * NOTE: 4.4.5 Included in Literal |
| 2360 | * When a parameter entity reference appears in a literal entity |
| 2361 | * value, ... a single or double quote character in the replacement |
| 2362 | * text is always treated as a normal data character and will not |
| 2363 | * terminate the literal. |
| 2364 | * In practice it means we stop the loop only when back at parsing |
| 2365 | * the initial entity and the quote is found |
| 2366 | */ |
| 2367 | while ((CUR != '"') || (ctxt->input != input)) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2368 | tst = CUR_PTR; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2369 | /* |
| 2370 | * NOTE: 4.4.7 Bypassed |
| 2371 | * When a general entity reference appears in the EntityValue in |
| 2372 | * an entity declaration, it is bypassed and left as is. |
| 2373 | * so XML_SUBSTITUTE_REF is not set. |
| 2374 | */ |
| 2375 | if (ctxt->input != input) |
| 2376 | temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, |
| 2377 | 0, 0, 0); |
| 2378 | else |
| 2379 | temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, |
| 2380 | '"', 0, 0); |
| 2381 | |
| 2382 | /* |
| 2383 | * Pop-up of finished entities. |
| 2384 | */ |
| 2385 | while ((CUR == 0) && (ctxt->inputNr > 1)) |
| 2386 | xmlPopInput(ctxt); |
| 2387 | |
| 2388 | if ((temp == NULL) && (tst == CUR_PTR)) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2389 | ret = xmlStrndup((xmlChar *) "", 0); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2390 | break; |
| 2391 | } |
| 2392 | if ((temp[0] == 0) && (tst == CUR_PTR)) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2393 | xmlFree((char *)temp); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2394 | ret = xmlStrndup((xmlChar *) "", 0); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2397 | ret = xmlStrcat(ret, temp); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2398 | if (temp != NULL) xmlFree((char *)temp); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2399 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2400 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2401 | if (CUR != '"') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2402 | ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2403 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2404 | ctxt->sax->error(ctxt->userData, "EntityValue: \" expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2405 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2406 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2407 | if (orig != NULL) /* !!!!!!!!! */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2408 | *orig = xmlStrndup(org, CUR_PTR - org); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2409 | if (ret == NULL) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2410 | ret = xmlStrndup((xmlChar *) "", 0); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2411 | NEXT; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2412 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2413 | } else if (CUR == '\'') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2414 | ctxt->instate = XML_PARSER_ENTITY_VALUE; |
| 2415 | input = ctxt->input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2416 | NEXT; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2417 | org = CUR_PTR; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2418 | /* |
| 2419 | * NOTE: 4.4.5 Included in Literal |
| 2420 | * When a parameter entity reference appears in a literal entity |
| 2421 | * value, ... a single or double quote character in the replacement |
| 2422 | * text is always treated as a normal data character and will not |
| 2423 | * terminate the literal. |
| 2424 | * In practice it means we stop the loop only when back at parsing |
| 2425 | * the initial entity and the quote is found |
| 2426 | */ |
| 2427 | while ((CUR != '\'') || (ctxt->input != input)) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2428 | tst = CUR_PTR; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2429 | /* |
| 2430 | * NOTE: 4.4.7 Bypassed |
| 2431 | * When a general entity reference appears in the EntityValue in |
| 2432 | * an entity declaration, it is bypassed and left as is. |
| 2433 | * so XML_SUBSTITUTE_REF is not set. |
| 2434 | */ |
| 2435 | if (ctxt->input != input) |
| 2436 | temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, |
| 2437 | 0, 0, 0); |
| 2438 | else |
| 2439 | temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, |
| 2440 | '\'', 0, 0); |
| 2441 | |
| 2442 | /* |
| 2443 | * Pop-up of finished entities. |
| 2444 | */ |
| 2445 | while ((CUR == 0) && (ctxt->inputNr > 1)) |
| 2446 | xmlPopInput(ctxt); |
| 2447 | |
| 2448 | if ((temp == NULL) && (tst == CUR_PTR)) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2449 | ret = xmlStrndup((xmlChar *) "", 0); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | } |
| 2452 | if ((temp[0] == 0) && (tst == CUR_PTR)) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2453 | xmlFree((char *)temp); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2454 | ret = xmlStrndup((xmlChar *) "", 0); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2455 | break; |
| 2456 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2457 | ret = xmlStrcat(ret, temp); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2458 | if (temp != NULL) xmlFree((char *)temp); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2459 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2460 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2461 | if (CUR != '\'') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2462 | ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2463 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2464 | ctxt->sax->error(ctxt->userData, "EntityValue: ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2465 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2466 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2467 | if (orig != NULL) /* !!!!!!!!! */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2468 | *orig = xmlStrndup(org, CUR_PTR - org); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2469 | if (ret == NULL) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2470 | ret = xmlStrndup((xmlChar *) "", 0); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2471 | NEXT; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2472 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2473 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2474 | ctxt->errNo = XML_ERR_ENTITY_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2475 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2476 | ctxt->sax->error(ctxt->userData, "EntityValue: \" or ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2477 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | return(ret); |
| 2481 | } |
| 2482 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2483 | /** |
| 2484 | * xmlParseAttValue: |
| 2485 | * @ctxt: an XML parser context |
| 2486 | * |
| 2487 | * parse a value for an attribute |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2488 | * Note: the parser won't do substitution of entities here, this |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2489 | * will be handled later in xmlStringGetNodeList |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2490 | * |
| 2491 | * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | |
| 2492 | * "'" ([^<&'] | Reference)* "'" |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2493 | * |
| 2494 | * Returns the AttValue parsed or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2495 | */ |
| 2496 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2497 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2498 | xmlParseAttValue(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2499 | xmlChar *ret = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2500 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2501 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2502 | if (CUR == '"') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2503 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2504 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2505 | ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_REF, '"', '<', 0); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2506 | if (CUR == '<') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2507 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2508 | ctxt->sax->error(ctxt->userData, |
| 2509 | "Unescaped '<' not allowed in attributes values\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2510 | ctxt->errNo = XML_ERR_LT_IN_ATTRIBUTE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2511 | ctxt->wellFormed = 0; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2512 | } |
| 2513 | if (CUR != '"') { |
| 2514 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2515 | ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2516 | ctxt->errNo = XML_ERR_ATTRIBUTE_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2517 | ctxt->wellFormed = 0; |
| 2518 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2519 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2520 | } else if (CUR == '\'') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2521 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2522 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2523 | ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_REF, '\'', '<', 0); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2524 | if (CUR == '<') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2525 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2526 | ctxt->sax->error(ctxt->userData, |
| 2527 | "Unescaped '<' not allowed in attributes values\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2528 | ctxt->errNo = XML_ERR_LT_IN_ATTRIBUTE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2529 | ctxt->wellFormed = 0; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2530 | } |
| 2531 | if (CUR != '\'') { |
| 2532 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2533 | ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2534 | ctxt->errNo = XML_ERR_ATTRIBUTE_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2535 | ctxt->wellFormed = 0; |
| 2536 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2537 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2538 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2539 | ctxt->errNo = XML_ERR_ATTRIBUTE_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2540 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2541 | ctxt->sax->error(ctxt->userData, "AttValue: \" or ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2542 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | return(ret); |
| 2546 | } |
| 2547 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2548 | /** |
| 2549 | * xmlParseSystemLiteral: |
| 2550 | * @ctxt: an XML parser context |
| 2551 | * |
| 2552 | * parse an XML Literal |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2553 | * |
| 2554 | * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2555 | * |
| 2556 | * Returns the SystemLiteral parsed or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2557 | */ |
| 2558 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2559 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2560 | xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2561 | const xmlChar *q; |
| 2562 | xmlChar *ret = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2563 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2564 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2565 | if (CUR == '"') { |
| 2566 | NEXT; |
| 2567 | q = CUR_PTR; |
| 2568 | while ((IS_CHAR(CUR)) && (CUR != '"')) |
| 2569 | NEXT; |
| 2570 | if (!IS_CHAR(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2571 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2572 | ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2573 | ctxt->errNo = XML_ERR_LITERAL_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2574 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2575 | } else { |
| 2576 | ret = xmlStrndup(q, CUR_PTR - q); |
| 2577 | NEXT; |
| 2578 | } |
| 2579 | } else if (CUR == '\'') { |
| 2580 | NEXT; |
| 2581 | q = CUR_PTR; |
| 2582 | while ((IS_CHAR(CUR)) && (CUR != '\'')) |
| 2583 | NEXT; |
| 2584 | if (!IS_CHAR(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2585 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2586 | ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2587 | ctxt->errNo = XML_ERR_LITERAL_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2588 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2589 | } else { |
| 2590 | ret = xmlStrndup(q, CUR_PTR - q); |
| 2591 | NEXT; |
| 2592 | } |
| 2593 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2594 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2595 | ctxt->sax->error(ctxt->userData, |
| 2596 | "SystemLiteral \" or ' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2597 | ctxt->errNo = XML_ERR_LITERAL_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2598 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | return(ret); |
| 2602 | } |
| 2603 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2604 | /** |
| 2605 | * xmlParsePubidLiteral: |
| 2606 | * @ctxt: an XML parser context |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2607 | * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2608 | * parse an XML public literal |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2609 | * |
| 2610 | * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" |
| 2611 | * |
| 2612 | * Returns the PubidLiteral parsed or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2613 | */ |
| 2614 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2615 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2616 | xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2617 | const xmlChar *q; |
| 2618 | xmlChar *ret = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2619 | /* |
| 2620 | * Name ::= (Letter | '_') (NameChar)* |
| 2621 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2622 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2623 | if (CUR == '"') { |
| 2624 | NEXT; |
| 2625 | q = CUR_PTR; |
| 2626 | while (IS_PUBIDCHAR(CUR)) NEXT; |
| 2627 | if (CUR != '"') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2628 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2629 | ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2630 | ctxt->errNo = XML_ERR_LITERAL_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2631 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2632 | } else { |
| 2633 | ret = xmlStrndup(q, CUR_PTR - q); |
| 2634 | NEXT; |
| 2635 | } |
| 2636 | } else if (CUR == '\'') { |
| 2637 | NEXT; |
| 2638 | q = CUR_PTR; |
| 2639 | while ((IS_LETTER(CUR)) && (CUR != '\'')) |
| 2640 | NEXT; |
| 2641 | if (!IS_LETTER(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2642 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2643 | ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2644 | ctxt->errNo = XML_ERR_LITERAL_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2645 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2646 | } else { |
| 2647 | ret = xmlStrndup(q, CUR_PTR - q); |
| 2648 | NEXT; |
| 2649 | } |
| 2650 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2651 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2652 | ctxt->sax->error(ctxt->userData, |
| 2653 | "SystemLiteral \" or ' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2654 | ctxt->errNo = XML_ERR_LITERAL_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2655 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | return(ret); |
| 2659 | } |
| 2660 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2661 | /** |
| 2662 | * xmlParseCharData: |
| 2663 | * @ctxt: an XML parser context |
| 2664 | * @cdata: int indicating whether we are within a CDATA section |
| 2665 | * |
| 2666 | * parse a CharData section. |
| 2667 | * if we are within a CDATA section ']]>' marks an end of section. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2668 | * |
| 2669 | * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) |
| 2670 | */ |
| 2671 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2672 | void |
| 2673 | xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2674 | xmlChar buf[1000]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2675 | int nbchar = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2676 | xmlChar cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2677 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2678 | SHRINK; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2679 | /* |
| 2680 | * !!!!!!!!!!!! |
| 2681 | * NOTE: NXT(0) is used here to avoid breaking on < or & |
| 2682 | * entities substitutions. |
| 2683 | */ |
| 2684 | cur = CUR; |
| 2685 | while ((IS_CHAR(cur)) && (cur != '<') && |
| 2686 | (cur != '&')) { |
| 2687 | if ((cur == ']') && (NXT(1) == ']') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2688 | (NXT(2) == '>')) { |
| 2689 | if (cdata) break; |
| 2690 | else { |
| 2691 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2692 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2693 | "Sequence ']]>' not allowed in content\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2694 | ctxt->errNo = XML_ERR_MISPLACED_CDATA_END; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2695 | ctxt->wellFormed = 0; |
| 2696 | } |
| 2697 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2698 | buf[nbchar++] = CUR; |
| 2699 | if (nbchar == 1000) { |
| 2700 | /* |
| 2701 | * Ok the segment is to be consumed as chars. |
| 2702 | */ |
| 2703 | if (ctxt->sax != NULL) { |
| 2704 | if (areBlanks(ctxt, buf, nbchar)) { |
| 2705 | if (ctxt->sax->ignorableWhitespace != NULL) |
| 2706 | ctxt->sax->ignorableWhitespace(ctxt->userData, |
| 2707 | buf, nbchar); |
| 2708 | } else { |
| 2709 | if (ctxt->sax->characters != NULL) |
| 2710 | ctxt->sax->characters(ctxt->userData, buf, nbchar); |
| 2711 | } |
| 2712 | } |
| 2713 | nbchar = 0; |
| 2714 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2715 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2716 | cur = CUR; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2717 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2718 | if (nbchar != 0) { |
| 2719 | /* |
| 2720 | * Ok the segment is to be consumed as chars. |
| 2721 | */ |
| 2722 | if (ctxt->sax != NULL) { |
| 2723 | if (areBlanks(ctxt, buf, nbchar)) { |
| 2724 | if (ctxt->sax->ignorableWhitespace != NULL) |
| 2725 | ctxt->sax->ignorableWhitespace(ctxt->userData, buf, nbchar); |
| 2726 | } else { |
| 2727 | if (ctxt->sax->characters != NULL) |
| 2728 | ctxt->sax->characters(ctxt->userData, buf, nbchar); |
| 2729 | } |
| 2730 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2734 | /** |
| 2735 | * xmlParseExternalID: |
| 2736 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2737 | * @publicID: a xmlChar** receiving PubidLiteral |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2738 | * @strict: indicate whether we should restrict parsing to only |
| 2739 | * production [75], see NOTE below |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2740 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2741 | * Parse an External ID or a Public ID |
| 2742 | * |
| 2743 | * NOTE: Productions [75] and [83] interract badly since [75] can generate |
| 2744 | * 'PUBLIC' S PubidLiteral S SystemLiteral |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2745 | * |
| 2746 | * [75] ExternalID ::= 'SYSTEM' S SystemLiteral |
| 2747 | * | 'PUBLIC' S PubidLiteral S SystemLiteral |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2748 | * |
| 2749 | * [83] PublicID ::= 'PUBLIC' S PubidLiteral |
| 2750 | * |
| 2751 | * Returns the function returns SystemLiteral and in the second |
| 2752 | * case publicID receives PubidLiteral, is strict is off |
| 2753 | * it is possible to return NULL and have publicID set. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2754 | */ |
| 2755 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2756 | xmlChar * |
| 2757 | xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict) { |
| 2758 | xmlChar *URI = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2759 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2760 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2761 | if ((CUR == 'S') && (NXT(1) == 'Y') && |
| 2762 | (NXT(2) == 'S') && (NXT(3) == 'T') && |
| 2763 | (NXT(4) == 'E') && (NXT(5) == 'M')) { |
| 2764 | SKIP(6); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2765 | if (!IS_BLANK(CUR)) { |
| 2766 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2767 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2768 | "Space required after 'SYSTEM'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2769 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2770 | ctxt->wellFormed = 0; |
| 2771 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2772 | SKIP_BLANKS; |
| 2773 | URI = xmlParseSystemLiteral(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2774 | if (URI == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2775 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2776 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2777 | "xmlParseExternalID: SYSTEM, no URI\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2778 | ctxt->errNo = XML_ERR_URI_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2779 | ctxt->wellFormed = 0; |
| 2780 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2781 | } else if ((CUR == 'P') && (NXT(1) == 'U') && |
| 2782 | (NXT(2) == 'B') && (NXT(3) == 'L') && |
| 2783 | (NXT(4) == 'I') && (NXT(5) == 'C')) { |
| 2784 | SKIP(6); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2785 | if (!IS_BLANK(CUR)) { |
| 2786 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2787 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2788 | "Space required after 'PUBLIC'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2789 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2790 | ctxt->wellFormed = 0; |
| 2791 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2792 | SKIP_BLANKS; |
| 2793 | *publicID = xmlParsePubidLiteral(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2794 | if (*publicID == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2795 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2796 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2797 | "xmlParseExternalID: PUBLIC, no Public Identifier\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2798 | ctxt->errNo = XML_ERR_PUBID_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2799 | ctxt->wellFormed = 0; |
| 2800 | } |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2801 | if (strict) { |
| 2802 | /* |
| 2803 | * We don't handle [83] so "S SystemLiteral" is required. |
| 2804 | */ |
| 2805 | if (!IS_BLANK(CUR)) { |
| 2806 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2807 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2808 | "Space required after the Public Identifier\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2809 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2810 | ctxt->wellFormed = 0; |
| 2811 | } |
| 2812 | } else { |
| 2813 | /* |
| 2814 | * We handle [83] so we return immediately, if |
| 2815 | * "S SystemLiteral" is not detected. From a purely parsing |
| 2816 | * point of view that's a nice mess. |
| 2817 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2818 | const xmlChar *ptr = CUR_PTR; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2819 | if (!IS_BLANK(*ptr)) return(NULL); |
| 2820 | |
| 2821 | while (IS_BLANK(*ptr)) ptr++; |
| 2822 | if ((*ptr != '\'') || (*ptr != '"')) return(NULL); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2823 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2824 | SKIP_BLANKS; |
| 2825 | URI = xmlParseSystemLiteral(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2826 | if (URI == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2827 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2828 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2829 | "xmlParseExternalID: PUBLIC, no URI\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2830 | ctxt->errNo = XML_ERR_URI_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2831 | ctxt->wellFormed = 0; |
| 2832 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2833 | } |
| 2834 | return(URI); |
| 2835 | } |
| 2836 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2837 | /** |
| 2838 | * xmlParseComment: |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2839 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2840 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2841 | * Skip an XML (SGML) comment <!-- .... --> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2842 | * The spec says that "For compatibility, the string "--" (double-hyphen) |
| 2843 | * must not occur within comments. " |
| 2844 | * |
| 2845 | * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' |
| 2846 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2847 | void |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2848 | xmlParseComment(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2849 | const xmlChar *q, *start; |
| 2850 | const xmlChar *r; |
| 2851 | xmlChar *val; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2852 | |
| 2853 | /* |
| 2854 | * Check that there is a comment right here. |
| 2855 | */ |
| 2856 | if ((CUR != '<') || (NXT(1) != '!') || |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2857 | (NXT(2) != '-') || (NXT(3) != '-')) return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2858 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2859 | ctxt->instate = XML_PARSER_COMMENT; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2860 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2861 | SKIP(4); |
| 2862 | start = q = CUR_PTR; |
| 2863 | NEXT; |
| 2864 | r = CUR_PTR; |
| 2865 | NEXT; |
| 2866 | while (IS_CHAR(CUR) && |
| 2867 | ((CUR == ':') || (CUR != '>') || |
| 2868 | (*r != '-') || (*q != '-'))) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2869 | if ((*r == '-') && (*q == '-')) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2870 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2871 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2872 | "Comment must not contain '--' (double-hyphen)`\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2873 | ctxt->errNo = XML_ERR_HYPHEN_IN_COMMENT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2874 | ctxt->wellFormed = 0; |
| 2875 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2876 | NEXT;r++;q++; |
| 2877 | } |
| 2878 | if (!IS_CHAR(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2879 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2880 | ctxt->sax->error(ctxt->userData, |
| 2881 | "Comment not terminated \n<!--%.50s\n", start); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2882 | ctxt->errNo = XML_ERR_COMMENT_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2883 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2884 | } else { |
| 2885 | NEXT; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2886 | val = xmlStrndup(start, q - start); |
| 2887 | if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL)) |
| 2888 | ctxt->sax->comment(ctxt->userData, val); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2889 | xmlFree(val); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2890 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2893 | /** |
| 2894 | * xmlParsePITarget: |
| 2895 | * @ctxt: an XML parser context |
| 2896 | * |
| 2897 | * parse the name of a PI |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2898 | * |
| 2899 | * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2900 | * |
| 2901 | * Returns the PITarget name or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2902 | */ |
| 2903 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2904 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2905 | xmlParsePITarget(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2906 | xmlChar *name; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2907 | |
| 2908 | name = xmlParseName(ctxt); |
| 2909 | if ((name != NULL) && (name[3] == 0) && |
| 2910 | ((name[0] == 'x') || (name[0] == 'X')) && |
| 2911 | ((name[1] == 'm') || (name[1] == 'M')) && |
| 2912 | ((name[2] == 'l') || (name[2] == 'L'))) { |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2913 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) { |
| 2914 | ctxt->sax->error(ctxt->userData, |
| 2915 | "xmlParsePItarget: invalid name prefix 'xml'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2916 | ctxt->errNo = XML_ERR_RESERVED_XML_NAME; |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2917 | /* ctxt->wellFormed = 0; !!! ? */ |
| 2918 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2919 | return(NULL); |
| 2920 | } |
| 2921 | return(name); |
| 2922 | } |
| 2923 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2924 | /** |
| 2925 | * xmlParsePI: |
| 2926 | * @ctxt: an XML parser context |
| 2927 | * |
| 2928 | * parse an XML Processing Instruction. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2929 | * |
| 2930 | * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2931 | * |
| 2932 | * The processing is transfered to SAX once parsed. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2933 | */ |
| 2934 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2935 | void |
| 2936 | xmlParsePI(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2937 | xmlChar *target; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2938 | |
| 2939 | if ((CUR == '<') && (NXT(1) == '?')) { |
| 2940 | /* |
| 2941 | * this is a Processing Instruction. |
| 2942 | */ |
| 2943 | SKIP(2); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2944 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2945 | |
| 2946 | /* |
| 2947 | * Parse the target name and check for special support like |
| 2948 | * namespace. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2949 | */ |
| 2950 | target = xmlParsePITarget(ctxt); |
| 2951 | if (target != NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2952 | const xmlChar *q; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2953 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2954 | if (!IS_BLANK(CUR)) { |
| 2955 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2956 | ctxt->sax->error(ctxt->userData, |
| 2957 | "xmlParsePI: PI %s space expected\n", target); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2958 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2959 | ctxt->wellFormed = 0; |
| 2960 | } |
| 2961 | SKIP_BLANKS; |
| 2962 | q = CUR_PTR; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2963 | while (IS_CHAR(CUR) && |
| 2964 | ((CUR != '?') || (NXT(1) != '>'))) |
| 2965 | NEXT; |
| 2966 | if (!IS_CHAR(CUR)) { |
| 2967 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2968 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2969 | "xmlParsePI: PI %s never end ...\n", target); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2970 | ctxt->errNo = XML_ERR_PI_NOT_FINISHED; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2971 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2972 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2973 | xmlChar *data; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2974 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2975 | data = xmlStrndup(q, CUR_PTR - q); |
| 2976 | SKIP(2); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2977 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2978 | /* |
| 2979 | * SAX: PI detected. |
| 2980 | */ |
| 2981 | if ((ctxt->sax) && |
| 2982 | (ctxt->sax->processingInstruction != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2983 | ctxt->sax->processingInstruction(ctxt->userData, |
| 2984 | target, data); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2985 | xmlFree(data); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2986 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2987 | xmlFree(target); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2988 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2989 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2990 | ctxt->sax->error(ctxt->userData, |
| 2991 | "xmlParsePI : no target name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2992 | ctxt->errNo = XML_ERR_PI_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2993 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2994 | } |
| 2995 | } |
| 2996 | } |
| 2997 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2998 | /** |
| 2999 | * xmlParseNotationDecl: |
| 3000 | * @ctxt: an XML parser context |
| 3001 | * |
| 3002 | * parse a notation declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3003 | * |
| 3004 | * [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>' |
| 3005 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3006 | * Hence there is actually 3 choices: |
| 3007 | * 'PUBLIC' S PubidLiteral |
| 3008 | * 'PUBLIC' S PubidLiteral S SystemLiteral |
| 3009 | * and 'SYSTEM' S SystemLiteral |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3010 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3011 | * See the NOTE on xmlParseExternalID(). |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3012 | */ |
| 3013 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 3014 | void |
| 3015 | xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3016 | xmlChar *name; |
| 3017 | xmlChar *Pubid; |
| 3018 | xmlChar *Systemid; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3019 | |
| 3020 | if ((CUR == '<') && (NXT(1) == '!') && |
| 3021 | (NXT(2) == 'N') && (NXT(3) == 'O') && |
| 3022 | (NXT(4) == 'T') && (NXT(5) == 'A') && |
| 3023 | (NXT(6) == 'T') && (NXT(7) == 'I') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3024 | (NXT(8) == 'O') && (NXT(9) == 'N')) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3025 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3026 | SKIP(10); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3027 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3028 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3029 | ctxt->sax->error(ctxt->userData, |
| 3030 | "Space required after '<!NOTATION'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3031 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3032 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3033 | return; |
| 3034 | } |
| 3035 | SKIP_BLANKS; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3036 | |
| 3037 | name = xmlParseName(ctxt); |
| 3038 | if (name == NULL) { |
| 3039 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3040 | ctxt->sax->error(ctxt->userData, |
| 3041 | "NOTATION: Name expected here\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3042 | ctxt->errNo = XML_ERR_NOTATION_NOT_STARTED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3043 | ctxt->wellFormed = 0; |
| 3044 | return; |
| 3045 | } |
| 3046 | if (!IS_BLANK(CUR)) { |
| 3047 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3048 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3049 | "Space required after the NOTATION name'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3050 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3051 | ctxt->wellFormed = 0; |
| 3052 | return; |
| 3053 | } |
| 3054 | SKIP_BLANKS; |
| 3055 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3056 | /* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3057 | * Parse the IDs. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3058 | */ |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3059 | Systemid = xmlParseExternalID(ctxt, &Pubid, 1); |
| 3060 | SKIP_BLANKS; |
| 3061 | |
| 3062 | if (CUR == '>') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3063 | NEXT; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 3064 | if ((ctxt->sax != NULL) && (ctxt->sax->notationDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3065 | ctxt->sax->notationDecl(ctxt->userData, name, Pubid, Systemid); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3066 | } else { |
| 3067 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3068 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3069 | "'>' required to close NOTATION declaration\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3070 | ctxt->errNo = XML_ERR_NOTATION_NOT_FINISHED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3071 | ctxt->wellFormed = 0; |
| 3072 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3073 | xmlFree(name); |
| 3074 | if (Systemid != NULL) xmlFree(Systemid); |
| 3075 | if (Pubid != NULL) xmlFree(Pubid); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3079 | /** |
| 3080 | * xmlParseEntityDecl: |
| 3081 | * @ctxt: an XML parser context |
| 3082 | * |
| 3083 | * parse <!ENTITY declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3084 | * |
| 3085 | * [70] EntityDecl ::= GEDecl | PEDecl |
| 3086 | * |
| 3087 | * [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>' |
| 3088 | * |
| 3089 | * [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>' |
| 3090 | * |
| 3091 | * [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?) |
| 3092 | * |
| 3093 | * [74] PEDef ::= EntityValue | ExternalID |
| 3094 | * |
| 3095 | * [76] NDataDecl ::= S 'NDATA' S Name |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3096 | * |
| 3097 | * [ VC: Notation Declared ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3098 | * The Name must match the declared name of a notation. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3099 | */ |
| 3100 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 3101 | void |
| 3102 | xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3103 | xmlChar *name = NULL; |
| 3104 | xmlChar *value = NULL; |
| 3105 | xmlChar *URI = NULL, *literal = NULL; |
| 3106 | xmlChar *ndata = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3107 | int isParameter = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3108 | xmlChar *orig = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3109 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3110 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3111 | if ((CUR == '<') && (NXT(1) == '!') && |
| 3112 | (NXT(2) == 'E') && (NXT(3) == 'N') && |
| 3113 | (NXT(4) == 'T') && (NXT(5) == 'I') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3114 | (NXT(6) == 'T') && (NXT(7) == 'Y')) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3115 | ctxt->instate = XML_PARSER_ENTITY_DECL; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3116 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3117 | SKIP(8); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3118 | if (!IS_BLANK(CUR)) { |
| 3119 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3120 | ctxt->sax->error(ctxt->userData, |
| 3121 | "Space required after '<!ENTITY'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3122 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3123 | ctxt->wellFormed = 0; |
| 3124 | } |
| 3125 | SKIP_BLANKS; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3126 | |
| 3127 | if (CUR == '%') { |
| 3128 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3129 | if (!IS_BLANK(CUR)) { |
| 3130 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3131 | ctxt->sax->error(ctxt->userData, |
| 3132 | "Space required after '%'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3133 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3134 | ctxt->wellFormed = 0; |
| 3135 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3136 | SKIP_BLANKS; |
| 3137 | isParameter = 1; |
| 3138 | } |
| 3139 | |
| 3140 | name = xmlParseName(ctxt); |
| 3141 | if (name == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3142 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3143 | ctxt->sax->error(ctxt->userData, "xmlParseEntityDecl: no name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3144 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3145 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3146 | return; |
| 3147 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3148 | if (!IS_BLANK(CUR)) { |
| 3149 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3150 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3151 | "Space required after the entity name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3152 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3153 | ctxt->wellFormed = 0; |
| 3154 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3155 | SKIP_BLANKS; |
| 3156 | |
| 3157 | /* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3158 | * handle the various case of definitions... |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3159 | */ |
| 3160 | if (isParameter) { |
| 3161 | if ((CUR == '"') || (CUR == '\'')) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3162 | value = xmlParseEntityValue(ctxt, &orig); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3163 | if (value) { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 3164 | if ((ctxt->sax != NULL) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3165 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3166 | XML_INTERNAL_PARAMETER_ENTITY, |
| 3167 | NULL, NULL, value); |
| 3168 | } |
| 3169 | else { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3170 | URI = xmlParseExternalID(ctxt, &literal, 1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3171 | if (URI) { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 3172 | if ((ctxt->sax != NULL) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3173 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3174 | XML_EXTERNAL_PARAMETER_ENTITY, |
| 3175 | literal, URI, NULL); |
| 3176 | } |
| 3177 | } |
| 3178 | } else { |
| 3179 | if ((CUR == '"') || (CUR == '\'')) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3180 | value = xmlParseEntityValue(ctxt, &orig); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 3181 | if ((ctxt->sax != NULL) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3182 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3183 | XML_INTERNAL_GENERAL_ENTITY, |
| 3184 | NULL, NULL, value); |
| 3185 | } else { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3186 | URI = xmlParseExternalID(ctxt, &literal, 1); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3187 | if ((CUR != '>') && (!IS_BLANK(CUR))) { |
| 3188 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3189 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3190 | "Space required before 'NDATA'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3191 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3192 | ctxt->wellFormed = 0; |
| 3193 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3194 | SKIP_BLANKS; |
| 3195 | if ((CUR == 'N') && (NXT(1) == 'D') && |
| 3196 | (NXT(2) == 'A') && (NXT(3) == 'T') && |
| 3197 | (NXT(4) == 'A')) { |
| 3198 | SKIP(5); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3199 | if (!IS_BLANK(CUR)) { |
| 3200 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3201 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3202 | "Space required after 'NDATA'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3203 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3204 | ctxt->wellFormed = 0; |
| 3205 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3206 | SKIP_BLANKS; |
| 3207 | ndata = xmlParseName(ctxt); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3208 | if ((ctxt->sax != NULL) && |
| 3209 | (ctxt->sax->unparsedEntityDecl != NULL)) |
| 3210 | ctxt->sax->unparsedEntityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3211 | literal, URI, ndata); |
| 3212 | } else { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 3213 | if ((ctxt->sax != NULL) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3214 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3215 | XML_EXTERNAL_GENERAL_PARSED_ENTITY, |
| 3216 | literal, URI, NULL); |
| 3217 | } |
| 3218 | } |
| 3219 | } |
| 3220 | SKIP_BLANKS; |
| 3221 | if (CUR != '>') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3222 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3223 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3224 | "xmlParseEntityDecl: entity %s not terminated\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3225 | ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3226 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3227 | } else |
| 3228 | NEXT; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3229 | if (orig != NULL) { |
| 3230 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3231 | * Ugly mechanism to save the raw entity value. |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3232 | */ |
| 3233 | xmlEntityPtr cur = NULL; |
| 3234 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3235 | if (isParameter) { |
| 3236 | if ((ctxt->sax != NULL) && |
| 3237 | (ctxt->sax->getParameterEntity != NULL)) |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 3238 | cur = ctxt->sax->getParameterEntity(ctxt->userData, name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3239 | } else { |
| 3240 | if ((ctxt->sax != NULL) && |
| 3241 | (ctxt->sax->getEntity != NULL)) |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 3242 | cur = ctxt->sax->getEntity(ctxt->userData, name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3243 | } |
| 3244 | if (cur != NULL) { |
| 3245 | if (cur->orig != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3246 | xmlFree(orig); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3247 | else |
| 3248 | cur->orig = orig; |
| 3249 | } else |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3250 | xmlFree(orig); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3251 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3252 | if (name != NULL) xmlFree(name); |
| 3253 | if (value != NULL) xmlFree(value); |
| 3254 | if (URI != NULL) xmlFree(URI); |
| 3255 | if (literal != NULL) xmlFree(literal); |
| 3256 | if (ndata != NULL) xmlFree(ndata); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3257 | } |
| 3258 | } |
| 3259 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3260 | /** |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3261 | * xmlParseDefaultDecl: |
| 3262 | * @ctxt: an XML parser context |
| 3263 | * @value: Receive a possible fixed default value for the attribute |
| 3264 | * |
| 3265 | * Parse an attribute default declaration |
| 3266 | * |
| 3267 | * [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) |
| 3268 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3269 | * [ VC: Required Attribute ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3270 | * if the default declaration is the keyword #REQUIRED, then the |
| 3271 | * attribute must be specified for all elements of the type in the |
| 3272 | * attribute-list declaration. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3273 | * |
| 3274 | * [ VC: Attribute Default Legal ] |
| 3275 | * The declared default value must meet the lexical constraints of |
| 3276 | * the declared attribute type c.f. xmlValidateAttributeDecl() |
| 3277 | * |
| 3278 | * [ VC: Fixed Attribute Default ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3279 | * if an attribute has a default value declared with the #FIXED |
| 3280 | * keyword, instances of that attribute must match the default value. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3281 | * |
| 3282 | * [ WFC: No < in Attribute Values ] |
| 3283 | * handled in xmlParseAttValue() |
| 3284 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3285 | * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED |
| 3286 | * or XML_ATTRIBUTE_FIXED. |
| 3287 | */ |
| 3288 | |
| 3289 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3290 | xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3291 | int val; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3292 | xmlChar *ret; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3293 | |
| 3294 | *value = NULL; |
| 3295 | if ((CUR == '#') && (NXT(1) == 'R') && |
| 3296 | (NXT(2) == 'E') && (NXT(3) == 'Q') && |
| 3297 | (NXT(4) == 'U') && (NXT(5) == 'I') && |
| 3298 | (NXT(6) == 'R') && (NXT(7) == 'E') && |
| 3299 | (NXT(8) == 'D')) { |
| 3300 | SKIP(9); |
| 3301 | return(XML_ATTRIBUTE_REQUIRED); |
| 3302 | } |
| 3303 | if ((CUR == '#') && (NXT(1) == 'I') && |
| 3304 | (NXT(2) == 'M') && (NXT(3) == 'P') && |
| 3305 | (NXT(4) == 'L') && (NXT(5) == 'I') && |
| 3306 | (NXT(6) == 'E') && (NXT(7) == 'D')) { |
| 3307 | SKIP(8); |
| 3308 | return(XML_ATTRIBUTE_IMPLIED); |
| 3309 | } |
| 3310 | val = XML_ATTRIBUTE_NONE; |
| 3311 | if ((CUR == '#') && (NXT(1) == 'F') && |
| 3312 | (NXT(2) == 'I') && (NXT(3) == 'X') && |
| 3313 | (NXT(4) == 'E') && (NXT(5) == 'D')) { |
| 3314 | SKIP(6); |
| 3315 | val = XML_ATTRIBUTE_FIXED; |
| 3316 | if (!IS_BLANK(CUR)) { |
| 3317 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3318 | ctxt->sax->error(ctxt->userData, |
| 3319 | "Space required after '#FIXED'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3320 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3321 | ctxt->wellFormed = 0; |
| 3322 | } |
| 3323 | SKIP_BLANKS; |
| 3324 | } |
| 3325 | ret = xmlParseAttValue(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3326 | ctxt->instate = XML_PARSER_DTD; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3327 | if (ret == NULL) { |
| 3328 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3329 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3330 | "Attribute default value declaration error\n"); |
| 3331 | ctxt->wellFormed = 0; |
| 3332 | } else |
| 3333 | *value = ret; |
| 3334 | return(val); |
| 3335 | } |
| 3336 | |
| 3337 | /** |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3338 | * xmlParseNotationType: |
| 3339 | * @ctxt: an XML parser context |
| 3340 | * |
| 3341 | * parse an Notation attribute type. |
| 3342 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3343 | * Note: the leading 'NOTATION' S part has already being parsed... |
| 3344 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3345 | * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' |
| 3346 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3347 | * [ VC: Notation Attributes ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3348 | * Values of this type must match one of the notation names included |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3349 | * in the declaration; all notation names in the declaration must be declared. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3350 | * |
| 3351 | * Returns: the notation attribute tree built while parsing |
| 3352 | */ |
| 3353 | |
| 3354 | xmlEnumerationPtr |
| 3355 | xmlParseNotationType(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3356 | xmlChar *name; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3357 | xmlEnumerationPtr ret = NULL, last = NULL, cur; |
| 3358 | |
| 3359 | if (CUR != '(') { |
| 3360 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3361 | ctxt->sax->error(ctxt->userData, |
| 3362 | "'(' required to start 'NOTATION'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3363 | ctxt->errNo = XML_ERR_NOTATION_NOT_STARTED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3364 | ctxt->wellFormed = 0; |
| 3365 | return(NULL); |
| 3366 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3367 | SHRINK; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3368 | do { |
| 3369 | NEXT; |
| 3370 | SKIP_BLANKS; |
| 3371 | name = xmlParseName(ctxt); |
| 3372 | if (name == NULL) { |
| 3373 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3374 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3375 | "Name expected in NOTATION declaration\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3376 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3377 | ctxt->wellFormed = 0; |
| 3378 | return(ret); |
| 3379 | } |
| 3380 | cur = xmlCreateEnumeration(name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3381 | xmlFree(name); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3382 | if (cur == NULL) return(ret); |
| 3383 | if (last == NULL) ret = last = cur; |
| 3384 | else { |
| 3385 | last->next = cur; |
| 3386 | last = cur; |
| 3387 | } |
| 3388 | SKIP_BLANKS; |
| 3389 | } while (CUR == '|'); |
| 3390 | if (CUR != ')') { |
| 3391 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3392 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3393 | "')' required to finish NOTATION declaration\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3394 | ctxt->errNo = XML_ERR_NOTATION_NOT_FINISHED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3395 | ctxt->wellFormed = 0; |
| 3396 | return(ret); |
| 3397 | } |
| 3398 | NEXT; |
| 3399 | return(ret); |
| 3400 | } |
| 3401 | |
| 3402 | /** |
| 3403 | * xmlParseEnumerationType: |
| 3404 | * @ctxt: an XML parser context |
| 3405 | * |
| 3406 | * parse an Enumeration attribute type. |
| 3407 | * |
| 3408 | * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' |
| 3409 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3410 | * [ VC: Enumeration ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3411 | * Values of this type must match one of the Nmtoken tokens in |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3412 | * the declaration |
| 3413 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3414 | * Returns: the enumeration attribute tree built while parsing |
| 3415 | */ |
| 3416 | |
| 3417 | xmlEnumerationPtr |
| 3418 | xmlParseEnumerationType(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3419 | xmlChar *name; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3420 | xmlEnumerationPtr ret = NULL, last = NULL, cur; |
| 3421 | |
| 3422 | if (CUR != '(') { |
| 3423 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3424 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3425 | "'(' required to start ATTLIST enumeration\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3426 | ctxt->errNo = XML_ERR_ATTLIST_NOT_STARTED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3427 | ctxt->wellFormed = 0; |
| 3428 | return(NULL); |
| 3429 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3430 | SHRINK; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3431 | do { |
| 3432 | NEXT; |
| 3433 | SKIP_BLANKS; |
| 3434 | name = xmlParseNmtoken(ctxt); |
| 3435 | if (name == NULL) { |
| 3436 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3437 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3438 | "NmToken expected in ATTLIST enumeration\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3439 | ctxt->errNo = XML_ERR_NMTOKEN_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3440 | ctxt->wellFormed = 0; |
| 3441 | return(ret); |
| 3442 | } |
| 3443 | cur = xmlCreateEnumeration(name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3444 | xmlFree(name); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3445 | if (cur == NULL) return(ret); |
| 3446 | if (last == NULL) ret = last = cur; |
| 3447 | else { |
| 3448 | last->next = cur; |
| 3449 | last = cur; |
| 3450 | } |
| 3451 | SKIP_BLANKS; |
| 3452 | } while (CUR == '|'); |
| 3453 | if (CUR != ')') { |
| 3454 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3455 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3456 | "')' required to finish ATTLIST enumeration\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3457 | ctxt->errNo = XML_ERR_ATTLIST_NOT_FINISHED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3458 | ctxt->wellFormed = 0; |
| 3459 | return(ret); |
| 3460 | } |
| 3461 | NEXT; |
| 3462 | return(ret); |
| 3463 | } |
| 3464 | |
| 3465 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3466 | * xmlParseEnumeratedType: |
| 3467 | * @ctxt: an XML parser context |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3468 | * @tree: the enumeration tree built while parsing |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3469 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3470 | * parse an Enumerated attribute type. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3471 | * |
| 3472 | * [57] EnumeratedType ::= NotationType | Enumeration |
| 3473 | * |
| 3474 | * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' |
| 3475 | * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3476 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3477 | * Returns: XML_ATTRIBUTE_ENUMERATION or XML_ATTRIBUTE_NOTATION |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3478 | */ |
| 3479 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3480 | int |
| 3481 | xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { |
| 3482 | if ((CUR == 'N') && (NXT(1) == 'O') && |
| 3483 | (NXT(2) == 'T') && (NXT(3) == 'A') && |
| 3484 | (NXT(4) == 'T') && (NXT(5) == 'I') && |
| 3485 | (NXT(6) == 'O') && (NXT(7) == 'N')) { |
| 3486 | SKIP(8); |
| 3487 | if (!IS_BLANK(CUR)) { |
| 3488 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3489 | ctxt->sax->error(ctxt->userData, |
| 3490 | "Space required after 'NOTATION'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3491 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3492 | ctxt->wellFormed = 0; |
| 3493 | return(0); |
| 3494 | } |
| 3495 | SKIP_BLANKS; |
| 3496 | *tree = xmlParseNotationType(ctxt); |
| 3497 | if (*tree == NULL) return(0); |
| 3498 | return(XML_ATTRIBUTE_NOTATION); |
| 3499 | } |
| 3500 | *tree = xmlParseEnumerationType(ctxt); |
| 3501 | if (*tree == NULL) return(0); |
| 3502 | return(XML_ATTRIBUTE_ENUMERATION); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3505 | /** |
| 3506 | * xmlParseAttributeType: |
| 3507 | * @ctxt: an XML parser context |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3508 | * @tree: the enumeration tree built while parsing |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3509 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3510 | * parse the Attribute list def for an element |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3511 | * |
| 3512 | * [54] AttType ::= StringType | TokenizedType | EnumeratedType |
| 3513 | * |
| 3514 | * [55] StringType ::= 'CDATA' |
| 3515 | * |
| 3516 | * [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | |
| 3517 | * 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3518 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3519 | * Validity constraints for attribute values syntax are checked in |
| 3520 | * xmlValidateAttributeValue() |
| 3521 | * |
| 3522 | * [ VC: ID ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3523 | * Values of type ID must match the Name production. A name must not |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3524 | * appear more than once in an XML document as a value of this type; |
| 3525 | * i.e., ID values must uniquely identify the elements which bear them. |
| 3526 | * |
| 3527 | * [ VC: One ID per Element Type ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3528 | * No element type may have more than one ID attribute specified. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3529 | * |
| 3530 | * [ VC: ID Attribute Default ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3531 | * An ID attribute must have a declared default of #IMPLIED or #REQUIRED. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3532 | * |
| 3533 | * [ VC: IDREF ] |
| 3534 | * Values of type IDREF must match the Name production, and values |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3535 | * of type IDREFS must match Names; TODO each IDREF Name must match the value |
| 3536 | * of an ID attribute on some element in the XML document; i.e. IDREF |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3537 | * values must match the value of some ID attribute. |
| 3538 | * |
| 3539 | * [ VC: Entity Name ] |
| 3540 | * Values of type ENTITY must match the Name production, values |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3541 | * of type ENTITIES must match Names; TODO each Entity Name must match the |
| 3542 | * name of an unparsed entity declared in the DTD. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3543 | * |
| 3544 | * [ VC: Name Token ] |
| 3545 | * Values of type NMTOKEN must match the Nmtoken production; values |
| 3546 | * of type NMTOKENS must match Nmtokens. |
| 3547 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3548 | * Returns the attribute type |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3549 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3550 | int |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3551 | xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3552 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3553 | if ((CUR == 'C') && (NXT(1) == 'D') && |
| 3554 | (NXT(2) == 'A') && (NXT(3) == 'T') && |
| 3555 | (NXT(4) == 'A')) { |
| 3556 | SKIP(5); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3557 | return(XML_ATTRIBUTE_CDATA); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3558 | } else if ((CUR == 'I') && (NXT(1) == 'D') && |
| 3559 | (NXT(2) == 'R') && (NXT(3) == 'E') && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3560 | (NXT(4) == 'F') && (NXT(5) == 'S')) { |
| 3561 | SKIP(6); |
| 3562 | return(XML_ATTRIBUTE_IDREFS); |
| 3563 | } else if ((CUR == 'I') && (NXT(1) == 'D') && |
| 3564 | (NXT(2) == 'R') && (NXT(3) == 'E') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3565 | (NXT(4) == 'F')) { |
| 3566 | SKIP(5); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3567 | return(XML_ATTRIBUTE_IDREF); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3568 | } else if ((CUR == 'I') && (NXT(1) == 'D')) { |
| 3569 | SKIP(2); |
| 3570 | return(XML_ATTRIBUTE_ID); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3571 | } else if ((CUR == 'E') && (NXT(1) == 'N') && |
| 3572 | (NXT(2) == 'T') && (NXT(3) == 'I') && |
| 3573 | (NXT(4) == 'T') && (NXT(5) == 'Y')) { |
| 3574 | SKIP(6); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3575 | return(XML_ATTRIBUTE_ENTITY); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3576 | } else if ((CUR == 'E') && (NXT(1) == 'N') && |
| 3577 | (NXT(2) == 'T') && (NXT(3) == 'I') && |
| 3578 | (NXT(4) == 'T') && (NXT(5) == 'I') && |
| 3579 | (NXT(6) == 'E') && (NXT(7) == 'S')) { |
| 3580 | SKIP(8); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3581 | return(XML_ATTRIBUTE_ENTITIES); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3582 | } else if ((CUR == 'N') && (NXT(1) == 'M') && |
| 3583 | (NXT(2) == 'T') && (NXT(3) == 'O') && |
| 3584 | (NXT(4) == 'K') && (NXT(5) == 'E') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3585 | (NXT(6) == 'N') && (NXT(7) == 'S')) { |
| 3586 | SKIP(8); |
| 3587 | return(XML_ATTRIBUTE_NMTOKENS); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3588 | } else if ((CUR == 'N') && (NXT(1) == 'M') && |
| 3589 | (NXT(2) == 'T') && (NXT(3) == 'O') && |
| 3590 | (NXT(4) == 'K') && (NXT(5) == 'E') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3591 | (NXT(6) == 'N')) { |
| 3592 | SKIP(7); |
| 3593 | return(XML_ATTRIBUTE_NMTOKEN); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3594 | } |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3595 | return(xmlParseEnumeratedType(ctxt, tree)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3596 | } |
| 3597 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3598 | /** |
| 3599 | * xmlParseAttributeListDecl: |
| 3600 | * @ctxt: an XML parser context |
| 3601 | * |
| 3602 | * : parse the Attribute list def for an element |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3603 | * |
| 3604 | * [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>' |
| 3605 | * |
| 3606 | * [53] AttDef ::= S Name S AttType S DefaultDecl |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3607 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3608 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 3609 | void |
| 3610 | xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3611 | xmlChar *elemName; |
| 3612 | xmlChar *attrName; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3613 | xmlEnumerationPtr tree; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3614 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3615 | if ((CUR == '<') && (NXT(1) == '!') && |
| 3616 | (NXT(2) == 'A') && (NXT(3) == 'T') && |
| 3617 | (NXT(4) == 'T') && (NXT(5) == 'L') && |
| 3618 | (NXT(6) == 'I') && (NXT(7) == 'S') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3619 | (NXT(8) == 'T')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3620 | SKIP(9); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3621 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3622 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3623 | ctxt->sax->error(ctxt->userData, |
| 3624 | "Space required after '<!ATTLIST'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3625 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3626 | ctxt->wellFormed = 0; |
| 3627 | } |
| 3628 | SKIP_BLANKS; |
| 3629 | elemName = xmlParseName(ctxt); |
| 3630 | if (elemName == NULL) { |
| 3631 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3632 | ctxt->sax->error(ctxt->userData, |
| 3633 | "ATTLIST: no name for Element\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3634 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3635 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3636 | return; |
| 3637 | } |
| 3638 | SKIP_BLANKS; |
| 3639 | while (CUR != '>') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3640 | const xmlChar *check = CUR_PTR; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3641 | int type; |
| 3642 | int def; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3643 | xmlChar *defaultValue = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3644 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3645 | tree = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3646 | attrName = xmlParseName(ctxt); |
| 3647 | if (attrName == NULL) { |
| 3648 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3649 | ctxt->sax->error(ctxt->userData, |
| 3650 | "ATTLIST: no name for Attribute\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3651 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3652 | ctxt->wellFormed = 0; |
| 3653 | break; |
| 3654 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3655 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3656 | if (!IS_BLANK(CUR)) { |
| 3657 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3658 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3659 | "Space required after the attribute name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3660 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3661 | ctxt->wellFormed = 0; |
| 3662 | break; |
| 3663 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3664 | SKIP_BLANKS; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3665 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3666 | type = xmlParseAttributeType(ctxt, &tree); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3667 | if (type <= 0) break; |
| 3668 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3669 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3670 | if (!IS_BLANK(CUR)) { |
| 3671 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3672 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3673 | "Space required after the attribute type\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3674 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3675 | ctxt->wellFormed = 0; |
| 3676 | break; |
| 3677 | } |
| 3678 | SKIP_BLANKS; |
| 3679 | |
| 3680 | def = xmlParseDefaultDecl(ctxt, &defaultValue); |
| 3681 | if (def <= 0) break; |
| 3682 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3683 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3684 | if (CUR != '>') { |
| 3685 | if (!IS_BLANK(CUR)) { |
| 3686 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3687 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3688 | "Space required after the attribute default value\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3689 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3690 | ctxt->wellFormed = 0; |
| 3691 | break; |
| 3692 | } |
| 3693 | SKIP_BLANKS; |
| 3694 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3695 | if (check == CUR_PTR) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3696 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3697 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3698 | "xmlParseAttributeListDecl: detected internal error\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3699 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3700 | break; |
| 3701 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 3702 | if ((ctxt->sax != NULL) && (ctxt->sax->attributeDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3703 | ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3704 | type, def, defaultValue, tree); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3705 | if (attrName != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3706 | xmlFree(attrName); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3707 | if (defaultValue != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3708 | xmlFree(defaultValue); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3709 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3710 | } |
| 3711 | if (CUR == '>') |
| 3712 | NEXT; |
| 3713 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3714 | xmlFree(elemName); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3718 | /** |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3719 | * xmlParseElementMixedContentDecl: |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3720 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3721 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3722 | * parse the declaration for a Mixed Element content |
| 3723 | * The leading '(' and spaces have been skipped in xmlParseElementContentDecl |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3724 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3725 | * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | |
| 3726 | * '(' S? '#PCDATA' S? ')' |
| 3727 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3728 | * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49]) |
| 3729 | * |
| 3730 | * [ VC: No Duplicate Types ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3731 | * The same name must not appear more than once in a single |
| 3732 | * mixed-content declaration. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3733 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3734 | * returns: the list of the xmlElementContentPtr describing the element choices |
| 3735 | */ |
| 3736 | xmlElementContentPtr |
| 3737 | xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3738 | xmlElementContentPtr ret = NULL, cur = NULL, n; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3739 | xmlChar *elem = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3740 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3741 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3742 | if ((CUR == '#') && (NXT(1) == 'P') && |
| 3743 | (NXT(2) == 'C') && (NXT(3) == 'D') && |
| 3744 | (NXT(4) == 'A') && (NXT(5) == 'T') && |
| 3745 | (NXT(6) == 'A')) { |
| 3746 | SKIP(7); |
| 3747 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3748 | SHRINK; |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 3749 | if (CUR == ')') { |
| 3750 | NEXT; |
| 3751 | ret = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_PCDATA); |
| 3752 | return(ret); |
| 3753 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3754 | if ((CUR == '(') || (CUR == '|')) { |
| 3755 | ret = cur = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_PCDATA); |
| 3756 | if (ret == NULL) return(NULL); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3757 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3758 | while (CUR == '|') { |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3759 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3760 | if (elem == NULL) { |
| 3761 | ret = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR); |
| 3762 | if (ret == NULL) return(NULL); |
| 3763 | ret->c1 = cur; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3764 | cur = ret; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3765 | } else { |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3766 | n = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR); |
| 3767 | if (n == NULL) return(NULL); |
| 3768 | n->c1 = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); |
| 3769 | cur->c2 = n; |
| 3770 | cur = n; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3771 | xmlFree(elem); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3772 | } |
| 3773 | SKIP_BLANKS; |
| 3774 | elem = xmlParseName(ctxt); |
| 3775 | if (elem == NULL) { |
| 3776 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3777 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3778 | "xmlParseElementMixedContentDecl : Name expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3779 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3780 | ctxt->wellFormed = 0; |
| 3781 | xmlFreeElementContent(cur); |
| 3782 | return(NULL); |
| 3783 | } |
| 3784 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3785 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3786 | } |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 3787 | if ((CUR == ')') && (NXT(1) == '*')) { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3788 | if (elem != NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3789 | cur->c2 = xmlNewElementContent(elem, |
| 3790 | XML_ELEMENT_CONTENT_ELEMENT); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3791 | xmlFree(elem); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3792 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3793 | ret->ocur = XML_ELEMENT_CONTENT_MULT; |
| 3794 | SKIP(2); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3795 | } else { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3796 | if (elem != NULL) xmlFree(elem); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3797 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3798 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 3799 | "xmlParseElementMixedContentDecl : '|' or ')*' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3800 | ctxt->errNo = XML_ERR_MIXED_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3801 | ctxt->wellFormed = 0; |
| 3802 | xmlFreeElementContent(ret); |
| 3803 | return(NULL); |
| 3804 | } |
| 3805 | |
| 3806 | } else { |
| 3807 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3808 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3809 | "xmlParseElementMixedContentDecl : '#PCDATA' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3810 | ctxt->errNo = XML_ERR_PCDATA_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3811 | ctxt->wellFormed = 0; |
| 3812 | } |
| 3813 | return(ret); |
| 3814 | } |
| 3815 | |
| 3816 | /** |
| 3817 | * xmlParseElementChildrenContentDecl: |
| 3818 | * @ctxt: an XML parser context |
| 3819 | * |
| 3820 | * parse the declaration for a Mixed Element content |
| 3821 | * The leading '(' and spaces have been skipped in xmlParseElementContentDecl |
| 3822 | * |
| 3823 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3824 | * [47] children ::= (choice | seq) ('?' | '*' | '+')? |
| 3825 | * |
| 3826 | * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? |
| 3827 | * |
| 3828 | * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')' |
| 3829 | * |
| 3830 | * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' |
| 3831 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3832 | * [ VC: Proper Group/PE Nesting ] applies to [49] and [50] |
| 3833 | * TODO Parameter-entity replacement text must be properly nested |
| 3834 | * with parenthetized groups. That is to say, if either of the |
| 3835 | * opening or closing parentheses in a choice, seq, or Mixed |
| 3836 | * construct is contained in the replacement text for a parameter |
| 3837 | * entity, both must be contained in the same replacement text. For |
| 3838 | * interoperability, if a parameter-entity reference appears in a |
| 3839 | * choice, seq, or Mixed construct, its replacement text should not |
| 3840 | * be empty, and neither the first nor last non-blank character of |
| 3841 | * the replacement text should be a connector (| or ,). |
| 3842 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3843 | * returns: the tree of xmlElementContentPtr describing the element |
| 3844 | * hierarchy. |
| 3845 | */ |
| 3846 | xmlElementContentPtr |
| 3847 | xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { |
| 3848 | xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3849 | xmlChar *elem; |
| 3850 | xmlChar type = 0; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3851 | |
| 3852 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3853 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3854 | if (CUR == '(') { |
| 3855 | /* Recurse on first child */ |
| 3856 | NEXT; |
| 3857 | SKIP_BLANKS; |
| 3858 | cur = ret = xmlParseElementChildrenContentDecl(ctxt); |
| 3859 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3860 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3861 | } else { |
| 3862 | elem = xmlParseName(ctxt); |
| 3863 | if (elem == NULL) { |
| 3864 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3865 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3866 | "xmlParseElementChildrenContentDecl : Name or '(' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3867 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3868 | ctxt->wellFormed = 0; |
| 3869 | return(NULL); |
| 3870 | } |
| 3871 | cur = ret = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3872 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3873 | if (CUR == '?') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3874 | cur->ocur = XML_ELEMENT_CONTENT_OPT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3875 | NEXT; |
| 3876 | } else if (CUR == '*') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3877 | cur->ocur = XML_ELEMENT_CONTENT_MULT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3878 | NEXT; |
| 3879 | } else if (CUR == '+') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3880 | cur->ocur = XML_ELEMENT_CONTENT_PLUS; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3881 | NEXT; |
| 3882 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3883 | cur->ocur = XML_ELEMENT_CONTENT_ONCE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3884 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3885 | xmlFree(elem); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3886 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3887 | } |
| 3888 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3889 | SHRINK; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3890 | while (CUR != ')') { |
| 3891 | /* |
| 3892 | * Each loop we parse one separator and one element. |
| 3893 | */ |
| 3894 | if (CUR == ',') { |
| 3895 | if (type == 0) type = CUR; |
| 3896 | |
| 3897 | /* |
| 3898 | * Detect "Name | Name , Name" error |
| 3899 | */ |
| 3900 | else if (type != CUR) { |
| 3901 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3902 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3903 | "xmlParseElementChildrenContentDecl : '%c' expected\n", |
| 3904 | type); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3905 | ctxt->errNo = XML_ERR_SEPARATOR_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3906 | ctxt->wellFormed = 0; |
| 3907 | xmlFreeElementContent(ret); |
| 3908 | return(NULL); |
| 3909 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3910 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3911 | |
| 3912 | op = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_SEQ); |
| 3913 | if (op == NULL) { |
| 3914 | xmlFreeElementContent(ret); |
| 3915 | return(NULL); |
| 3916 | } |
| 3917 | if (last == NULL) { |
| 3918 | op->c1 = ret; |
| 3919 | ret = cur = op; |
| 3920 | } else { |
| 3921 | cur->c2 = op; |
| 3922 | op->c1 = last; |
| 3923 | cur =op; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3924 | last = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3925 | } |
| 3926 | } else if (CUR == '|') { |
| 3927 | if (type == 0) type = CUR; |
| 3928 | |
| 3929 | /* |
| 3930 | * Detect "Name , Name | Name" error |
| 3931 | */ |
| 3932 | else if (type != CUR) { |
| 3933 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3934 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3935 | "xmlParseElementChildrenContentDecl : '%c' expected\n", |
| 3936 | type); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3937 | ctxt->errNo = XML_ERR_SEPARATOR_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3938 | ctxt->wellFormed = 0; |
| 3939 | xmlFreeElementContent(ret); |
| 3940 | return(NULL); |
| 3941 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3942 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3943 | |
| 3944 | op = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR); |
| 3945 | if (op == NULL) { |
| 3946 | xmlFreeElementContent(ret); |
| 3947 | return(NULL); |
| 3948 | } |
| 3949 | if (last == NULL) { |
| 3950 | op->c1 = ret; |
| 3951 | ret = cur = op; |
| 3952 | } else { |
| 3953 | cur->c2 = op; |
| 3954 | op->c1 = last; |
| 3955 | cur =op; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3956 | last = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3957 | } |
| 3958 | } else { |
| 3959 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3960 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3961 | "xmlParseElementChildrenContentDecl : ',' '|' or ')' expected\n"); |
| 3962 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3963 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3964 | xmlFreeElementContent(ret); |
| 3965 | return(NULL); |
| 3966 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3967 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3968 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3969 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3970 | if (CUR == '(') { |
| 3971 | /* Recurse on second child */ |
| 3972 | NEXT; |
| 3973 | SKIP_BLANKS; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3974 | last = xmlParseElementChildrenContentDecl(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3975 | SKIP_BLANKS; |
| 3976 | } else { |
| 3977 | elem = xmlParseName(ctxt); |
| 3978 | if (elem == NULL) { |
| 3979 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3980 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3981 | "xmlParseElementChildrenContentDecl : Name or '(' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3982 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3983 | ctxt->wellFormed = 0; |
| 3984 | return(NULL); |
| 3985 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3986 | last = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3987 | xmlFree(elem); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3988 | if (CUR == '?') { |
| 3989 | last->ocur = XML_ELEMENT_CONTENT_OPT; |
| 3990 | NEXT; |
| 3991 | } else if (CUR == '*') { |
| 3992 | last->ocur = XML_ELEMENT_CONTENT_MULT; |
| 3993 | NEXT; |
| 3994 | } else if (CUR == '+') { |
| 3995 | last->ocur = XML_ELEMENT_CONTENT_PLUS; |
| 3996 | NEXT; |
| 3997 | } else { |
| 3998 | last->ocur = XML_ELEMENT_CONTENT_ONCE; |
| 3999 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4000 | } |
| 4001 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4002 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4003 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 4004 | if ((cur != NULL) && (last != NULL)) { |
| 4005 | cur->c2 = last; |
| 4006 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4007 | NEXT; |
| 4008 | if (CUR == '?') { |
| 4009 | ret->ocur = XML_ELEMENT_CONTENT_OPT; |
| 4010 | NEXT; |
| 4011 | } else if (CUR == '*') { |
| 4012 | ret->ocur = XML_ELEMENT_CONTENT_MULT; |
| 4013 | NEXT; |
| 4014 | } else if (CUR == '+') { |
| 4015 | ret->ocur = XML_ELEMENT_CONTENT_PLUS; |
| 4016 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4017 | } |
| 4018 | return(ret); |
| 4019 | } |
| 4020 | |
| 4021 | /** |
| 4022 | * xmlParseElementContentDecl: |
| 4023 | * @ctxt: an XML parser context |
| 4024 | * @name: the name of the element being defined. |
| 4025 | * @result: the Element Content pointer will be stored here if any |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4026 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4027 | * parse the declaration for an Element content either Mixed or Children, |
| 4028 | * the cases EMPTY and ANY are handled directly in xmlParseElementDecl |
| 4029 | * |
| 4030 | * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4031 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4032 | * returns: the type of element content XML_ELEMENT_TYPE_xxx |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4033 | */ |
| 4034 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4035 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4036 | xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, xmlChar *name, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4037 | xmlElementContentPtr *result) { |
| 4038 | |
| 4039 | xmlElementContentPtr tree = NULL; |
| 4040 | int res; |
| 4041 | |
| 4042 | *result = NULL; |
| 4043 | |
| 4044 | if (CUR != '(') { |
| 4045 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4046 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4047 | "xmlParseElementContentDecl : '(' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4048 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4049 | ctxt->wellFormed = 0; |
| 4050 | return(-1); |
| 4051 | } |
| 4052 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4053 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4054 | SKIP_BLANKS; |
| 4055 | if ((CUR == '#') && (NXT(1) == 'P') && |
| 4056 | (NXT(2) == 'C') && (NXT(3) == 'D') && |
| 4057 | (NXT(4) == 'A') && (NXT(5) == 'T') && |
| 4058 | (NXT(6) == 'A')) { |
| 4059 | tree = xmlParseElementMixedContentDecl(ctxt); |
| 4060 | res = XML_ELEMENT_TYPE_MIXED; |
| 4061 | } else { |
| 4062 | tree = xmlParseElementChildrenContentDecl(ctxt); |
| 4063 | res = XML_ELEMENT_TYPE_ELEMENT; |
| 4064 | } |
| 4065 | SKIP_BLANKS; |
| 4066 | /**************************** |
| 4067 | if (CUR != ')') { |
| 4068 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4069 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4070 | "xmlParseElementContentDecl : ')' expected\n"); |
| 4071 | ctxt->wellFormed = 0; |
| 4072 | return(-1); |
| 4073 | } |
| 4074 | ****************************/ |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 4075 | *result = tree; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4076 | return(res); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4077 | } |
| 4078 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4079 | /** |
| 4080 | * xmlParseElementDecl: |
| 4081 | * @ctxt: an XML parser context |
| 4082 | * |
| 4083 | * parse an Element declaration. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4084 | * |
| 4085 | * [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>' |
| 4086 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4087 | * [ VC: Unique Element Type Declaration ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4088 | * No element type may be declared more than once |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4089 | * |
| 4090 | * Returns the type of the element, or -1 in case of error |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4091 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4092 | int |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4093 | xmlParseElementDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4094 | xmlChar *name; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4095 | int ret = -1; |
| 4096 | xmlElementContentPtr content = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4097 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4098 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4099 | if ((CUR == '<') && (NXT(1) == '!') && |
| 4100 | (NXT(2) == 'E') && (NXT(3) == 'L') && |
| 4101 | (NXT(4) == 'E') && (NXT(5) == 'M') && |
| 4102 | (NXT(6) == 'E') && (NXT(7) == 'N') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4103 | (NXT(8) == 'T')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4104 | SKIP(9); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4105 | if (!IS_BLANK(CUR)) { |
| 4106 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4107 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4108 | "Space required after 'ELEMENT'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4109 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4110 | ctxt->wellFormed = 0; |
| 4111 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4112 | SKIP_BLANKS; |
| 4113 | name = xmlParseName(ctxt); |
| 4114 | if (name == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4115 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4116 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4117 | "xmlParseElementDecl: no name for Element\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4118 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4119 | ctxt->wellFormed = 0; |
| 4120 | return(-1); |
| 4121 | } |
| 4122 | if (!IS_BLANK(CUR)) { |
| 4123 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4124 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4125 | "Space required after the element name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4126 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4127 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4128 | } |
| 4129 | SKIP_BLANKS; |
| 4130 | if ((CUR == 'E') && (NXT(1) == 'M') && |
| 4131 | (NXT(2) == 'P') && (NXT(3) == 'T') && |
| 4132 | (NXT(4) == 'Y')) { |
| 4133 | SKIP(5); |
| 4134 | /* |
| 4135 | * Element must always be empty. |
| 4136 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4137 | ret = XML_ELEMENT_TYPE_EMPTY; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4138 | } else if ((CUR == 'A') && (NXT(1) == 'N') && |
| 4139 | (NXT(2) == 'Y')) { |
| 4140 | SKIP(3); |
| 4141 | /* |
| 4142 | * Element is a generic container. |
| 4143 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4144 | ret = XML_ELEMENT_TYPE_ANY; |
| 4145 | } else if (CUR == '(') { |
| 4146 | ret = xmlParseElementContentDecl(ctxt, name, &content); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4147 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4148 | /* |
| 4149 | * [ WFC: PEs in Internal Subset ] error handling. |
| 4150 | */ |
| 4151 | if ((CUR == '%') && (ctxt->external == 0) && |
| 4152 | (ctxt->inputNr == 1)) { |
| 4153 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4154 | ctxt->sax->error(ctxt->userData, |
| 4155 | "PEReference: forbidden within markup decl in internal subset\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4156 | ctxt->errNo = XML_ERR_PEREF_IN_INT_SUBSET; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4157 | } else { |
| 4158 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4159 | ctxt->sax->error(ctxt->userData, |
| 4160 | "xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4161 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4162 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4163 | ctxt->wellFormed = 0; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4164 | if (name != NULL) xmlFree(name); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4165 | return(-1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4166 | } |
| 4167 | SKIP_BLANKS; |
| 4168 | if (CUR != '>') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4169 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4170 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4171 | "xmlParseElementDecl: expected '>' at the end\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4172 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4173 | ctxt->wellFormed = 0; |
| 4174 | } else { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4175 | NEXT; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4176 | if ((ctxt->sax != NULL) && (ctxt->sax->elementDecl != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4177 | ctxt->sax->elementDecl(ctxt->userData, name, ret, |
| 4178 | content); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4179 | } |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 4180 | if (content != NULL) { |
| 4181 | xmlFreeElementContent(content); |
| 4182 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4183 | if (name != NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4184 | xmlFree(name); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4185 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4186 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4187 | return(ret); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4188 | } |
| 4189 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4190 | /** |
| 4191 | * xmlParseMarkupDecl: |
| 4192 | * @ctxt: an XML parser context |
| 4193 | * |
| 4194 | * parse Markup declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4195 | * |
| 4196 | * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | |
| 4197 | * NotationDecl | PI | Comment |
| 4198 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4199 | * [ VC: Proper Declaration/PE Nesting ] |
| 4200 | * TODO Parameter-entity replacement text must be properly nested with |
| 4201 | * markup declarations. That is to say, if either the first character |
| 4202 | * or the last character of a markup declaration (markupdecl above) is |
| 4203 | * contained in the replacement text for a parameter-entity reference, |
| 4204 | * both must be contained in the same replacement text. |
| 4205 | * |
| 4206 | * [ WFC: PEs in Internal Subset ] |
| 4207 | * In the internal DTD subset, parameter-entity references can occur |
| 4208 | * only where markup declarations can occur, not within markup declarations. |
| 4209 | * (This does not apply to references that occur in external parameter |
| 4210 | * entities or to the external subset.) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4211 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4212 | void |
| 4213 | xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4214 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4215 | xmlParseElementDecl(ctxt); |
| 4216 | xmlParseAttributeListDecl(ctxt); |
| 4217 | xmlParseEntityDecl(ctxt); |
| 4218 | xmlParseNotationDecl(ctxt); |
| 4219 | xmlParsePI(ctxt); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4220 | xmlParseComment(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4221 | /* |
| 4222 | * This is only for internal subset. On external entities, |
| 4223 | * the replacement is done before parsing stage |
| 4224 | */ |
| 4225 | if ((ctxt->external == 0) && (ctxt->inputNr == 1)) |
| 4226 | xmlParsePEReference(ctxt); |
| 4227 | ctxt->instate = XML_PARSER_DTD; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4230 | /** |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4231 | * xmlParseTextDecl: |
| 4232 | * @ctxt: an XML parser context |
| 4233 | * |
| 4234 | * parse an XML declaration header for external entities |
| 4235 | * |
| 4236 | * [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>' |
| 4237 | * |
| 4238 | * Returns the only valuable info for an external parsed entity, the encoding |
| 4239 | */ |
| 4240 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4241 | xmlChar * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4242 | xmlParseTextDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4243 | xmlChar *version; |
| 4244 | xmlChar *encoding = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4245 | |
| 4246 | /* |
| 4247 | * We know that '<?xml' is here. |
| 4248 | */ |
| 4249 | SKIP(5); |
| 4250 | |
| 4251 | if (!IS_BLANK(CUR)) { |
| 4252 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4253 | ctxt->sax->error(ctxt->userData, |
| 4254 | "Space needed after '<?xml'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4255 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4256 | ctxt->wellFormed = 0; |
| 4257 | } |
| 4258 | SKIP_BLANKS; |
| 4259 | |
| 4260 | /* |
| 4261 | * We may have the VersionInfo here. |
| 4262 | */ |
| 4263 | version = xmlParseVersionInfo(ctxt); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4264 | if (version == NULL) |
| 4265 | version = xmlCharStrdup(XML_DEFAULT_VERSION); |
| 4266 | ctxt->version = xmlStrdup(version); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4267 | xmlFree(version); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4268 | |
| 4269 | /* |
| 4270 | * We must have the encoding declaration |
| 4271 | */ |
| 4272 | if (!IS_BLANK(CUR)) { |
| 4273 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4274 | ctxt->sax->error(ctxt->userData, "Space needed here\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4275 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4276 | ctxt->wellFormed = 0; |
| 4277 | } |
| 4278 | encoding = xmlParseEncodingDecl(ctxt); |
| 4279 | |
| 4280 | SKIP_BLANKS; |
| 4281 | if ((CUR == '?') && (NXT(1) == '>')) { |
| 4282 | SKIP(2); |
| 4283 | } else if (CUR == '>') { |
| 4284 | /* Deprecated old WD ... */ |
| 4285 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4286 | ctxt->sax->error(ctxt->userData, |
| 4287 | "XML declaration must end-up with '?>'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4288 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4289 | ctxt->wellFormed = 0; |
| 4290 | NEXT; |
| 4291 | } else { |
| 4292 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4293 | ctxt->sax->error(ctxt->userData, |
| 4294 | "parsing XML declaration: '?>' expected\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4295 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4296 | ctxt->wellFormed = 0; |
| 4297 | MOVETO_ENDTAG(CUR_PTR); |
| 4298 | NEXT; |
| 4299 | } |
| 4300 | return(encoding); |
| 4301 | } |
| 4302 | |
| 4303 | /* |
| 4304 | * xmlParseConditionalSections |
| 4305 | * @ctxt: an XML parser context |
| 4306 | * |
| 4307 | * TODO : Conditionnal section are not yet supported ! |
| 4308 | * |
| 4309 | * [61] conditionalSect ::= includeSect | ignoreSect |
| 4310 | * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' |
| 4311 | * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' |
| 4312 | * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* |
| 4313 | * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*) |
| 4314 | */ |
| 4315 | |
| 4316 | void |
| 4317 | xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { |
| 4318 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 4319 | ctxt->sax->warning(ctxt->userData, |
| 4320 | "XML conditional section not supported\n"); |
| 4321 | /* |
| 4322 | * Skip up to the end of the conditionnal section. |
| 4323 | */ |
| 4324 | while ((CUR != 0) && ((CUR != ']') || (NXT(1) != ']') || (NXT(2) != '>'))) |
| 4325 | NEXT; |
| 4326 | if (CUR == 0) { |
| 4327 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4328 | ctxt->sax->error(ctxt->userData, |
| 4329 | "XML conditional section not closed\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4330 | ctxt->errNo = XML_ERR_CONDSEC_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4331 | ctxt->wellFormed = 0; |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | /** |
| 4336 | * xmlParseExternalSubset |
| 4337 | * @ctxt: an XML parser context |
| 4338 | * |
| 4339 | * parse Markup declarations from an external subset |
| 4340 | * |
| 4341 | * [30] extSubset ::= textDecl? extSubsetDecl |
| 4342 | * |
| 4343 | * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4344 | */ |
| 4345 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4346 | xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, |
| 4347 | const xmlChar *SystemID) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4348 | if ((CUR == '<') && (NXT(1) == '?') && |
| 4349 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 4350 | (NXT(4) == 'l')) { |
| 4351 | xmlParseTextDecl(ctxt); |
| 4352 | } |
| 4353 | if (ctxt->myDoc == NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4354 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4355 | } |
| 4356 | if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL)) |
| 4357 | xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID); |
| 4358 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4359 | ctxt->instate = XML_PARSER_DTD; |
| 4360 | ctxt->external = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4361 | while (((CUR == '<') && (NXT(1) == '?')) || |
| 4362 | ((CUR == '<') && (NXT(1) == '!')) || |
| 4363 | IS_BLANK(CUR)) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4364 | const xmlChar *check = CUR_PTR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4365 | int cons = ctxt->input->consumed; |
| 4366 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4367 | if ((CUR == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { |
| 4368 | xmlParseConditionalSections(ctxt); |
| 4369 | } else if (IS_BLANK(CUR)) { |
| 4370 | NEXT; |
| 4371 | } else if (CUR == '%') { |
| 4372 | xmlParsePEReference(ctxt); |
| 4373 | } else |
| 4374 | xmlParseMarkupDecl(ctxt); |
| 4375 | |
| 4376 | /* |
| 4377 | * Pop-up of finished entities. |
| 4378 | */ |
| 4379 | while ((CUR == 0) && (ctxt->inputNr > 1)) |
| 4380 | xmlPopInput(ctxt); |
| 4381 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4382 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { |
| 4383 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4384 | ctxt->sax->error(ctxt->userData, |
| 4385 | "Content error in the external subset\n"); |
| 4386 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4387 | ctxt->errNo = XML_ERR_EXT_SUBSET_NOT_FINISHED; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4388 | break; |
| 4389 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | if (CUR != 0) { |
| 4393 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4394 | ctxt->sax->error(ctxt->userData, |
| 4395 | "Extra content at the end of the document\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4396 | ctxt->errNo = XML_ERR_EXT_SUBSET_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4397 | ctxt->wellFormed = 0; |
| 4398 | } |
| 4399 | |
| 4400 | } |
| 4401 | |
| 4402 | /** |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4403 | * xmlParseReference: |
| 4404 | * @ctxt: an XML parser context |
| 4405 | * |
| 4406 | * parse and handle entity references in content, depending on the SAX |
| 4407 | * interface, this may end-up in a call to character() if this is a |
| 4408 | * CharRef, a predefined entity, if there is no reference() callback. |
| 4409 | * or if the parser was asked to switch to that mode. |
| 4410 | * |
| 4411 | * [67] Reference ::= EntityRef | CharRef |
| 4412 | */ |
| 4413 | void |
| 4414 | xmlParseReference(xmlParserCtxtPtr ctxt) { |
| 4415 | xmlEntityPtr ent; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4416 | xmlChar *val; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4417 | if (CUR != '&') return; |
| 4418 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4419 | if (ctxt->inputNr > 1) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4420 | xmlChar cur[2] = { '&' , 0 } ; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4421 | |
| 4422 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) |
| 4423 | ctxt->sax->characters(ctxt->userData, cur, 1); |
| 4424 | if (ctxt->token == '&') |
| 4425 | ctxt->token = 0; |
| 4426 | else { |
| 4427 | SKIP(1); |
| 4428 | } |
| 4429 | return; |
| 4430 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4431 | if (NXT(1) == '#') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4432 | xmlChar out[2]; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4433 | int val = xmlParseCharRef(ctxt); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4434 | /* invalid for UTF-8 variable encoding !!!!! */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4435 | out[0] = val; |
| 4436 | out[1] = 0; |
| 4437 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) |
| 4438 | ctxt->sax->characters(ctxt->userData, out, 1); |
| 4439 | } else { |
| 4440 | ent = xmlParseEntityRef(ctxt); |
| 4441 | if (ent == NULL) return; |
| 4442 | if ((ent->name != NULL) && |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4443 | (ent->type != XML_INTERNAL_PREDEFINED_ENTITY)) { |
| 4444 | if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) && |
| 4445 | (ctxt->replaceEntities == 0)) { |
| 4446 | /* |
| 4447 | * Create a node. |
| 4448 | */ |
| 4449 | ctxt->sax->reference(ctxt->userData, ent->name); |
| 4450 | return; |
| 4451 | } else if (ctxt->replaceEntities) { |
| 4452 | xmlParserInputPtr input; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4453 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4454 | input = xmlNewEntityInputStream(ctxt, ent); |
| 4455 | xmlPushInput(ctxt, input); |
| 4456 | return; |
| 4457 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4458 | } |
| 4459 | val = ent->content; |
| 4460 | if (val == NULL) return; |
| 4461 | /* |
| 4462 | * inline the entity. |
| 4463 | */ |
| 4464 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) |
| 4465 | ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val)); |
| 4466 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4467 | } |
| 4468 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4469 | /** |
| 4470 | * xmlParseEntityRef: |
| 4471 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4472 | * |
| 4473 | * parse ENTITY references declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4474 | * |
| 4475 | * [68] EntityRef ::= '&' Name ';' |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4476 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4477 | * [ WFC: Entity Declared ] |
| 4478 | * In a document without any DTD, a document with only an internal DTD |
| 4479 | * subset which contains no parameter entity references, or a document |
| 4480 | * with "standalone='yes'", the Name given in the entity reference |
| 4481 | * must match that in an entity declaration, except that well-formed |
| 4482 | * documents need not declare any of the following entities: amp, lt, |
| 4483 | * gt, apos, quot. The declaration of a parameter entity must precede |
| 4484 | * any reference to it. Similarly, the declaration of a general entity |
| 4485 | * must precede any reference to it which appears in a default value in an |
| 4486 | * attribute-list declaration. Note that if entities are declared in the |
| 4487 | * external subset or in external parameter entities, a non-validating |
| 4488 | * processor is not obligated to read and process their declarations; |
| 4489 | * for such documents, the rule that an entity must be declared is a |
| 4490 | * well-formedness constraint only if standalone='yes'. |
| 4491 | * |
| 4492 | * [ WFC: Parsed Entity ] |
| 4493 | * An entity reference must not contain the name of an unparsed entity |
| 4494 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4495 | * Returns the xmlEntityPtr if found, or NULL otherwise. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4496 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4497 | xmlEntityPtr |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4498 | xmlParseEntityRef(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4499 | xmlChar *name; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4500 | xmlEntityPtr ent = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4501 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 4502 | GROW; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4503 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4504 | if (CUR == '&') { |
| 4505 | NEXT; |
| 4506 | name = xmlParseName(ctxt); |
| 4507 | if (name == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4508 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4509 | ctxt->sax->error(ctxt->userData, |
| 4510 | "xmlParseEntityRef: no name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4511 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4512 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4513 | } else { |
| 4514 | if (CUR == ';') { |
| 4515 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4516 | /* |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4517 | * Ask first SAX for entity resolution, otherwise try the |
| 4518 | * predefined set. |
| 4519 | */ |
| 4520 | if (ctxt->sax != NULL) { |
| 4521 | if (ctxt->sax->getEntity != NULL) |
| 4522 | ent = ctxt->sax->getEntity(ctxt->userData, name); |
| 4523 | if (ent == NULL) |
| 4524 | ent = xmlGetPredefinedEntity(name); |
| 4525 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4526 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4527 | * [ WFC: Entity Declared ] |
| 4528 | * In a document without any DTD, a document with only an |
| 4529 | * internal DTD subset which contains no parameter entity |
| 4530 | * references, or a document with "standalone='yes'", the |
| 4531 | * Name given in the entity reference must match that in an |
| 4532 | * entity declaration, except that well-formed documents |
| 4533 | * need not declare any of the following entities: amp, lt, |
| 4534 | * gt, apos, quot. |
| 4535 | * The declaration of a parameter entity must precede any |
| 4536 | * reference to it. |
| 4537 | * Similarly, the declaration of a general entity must |
| 4538 | * precede any reference to it which appears in a default |
| 4539 | * value in an attribute-list declaration. Note that if |
| 4540 | * entities are declared in the external subset or in |
| 4541 | * external parameter entities, a non-validating processor |
| 4542 | * is not obligated to read and process their declarations; |
| 4543 | * for such documents, the rule that an entity must be |
| 4544 | * declared is a well-formedness constraint only if |
| 4545 | * standalone='yes'. |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4546 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4547 | if (ent == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4548 | if ((ctxt->standalone == 1) || |
| 4549 | ((ctxt->hasExternalSubset == 0) && |
| 4550 | (ctxt->hasPErefs == 0))) { |
| 4551 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4552 | ctxt->sax->error(ctxt->userData, |
| 4553 | "Entity '%s' not defined\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4554 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4555 | ctxt->wellFormed = 0; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4556 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4557 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 4558 | ctxt->sax->warning(ctxt->userData, |
| 4559 | "Entity '%s' not defined\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4560 | ctxt->errNo = XML_WAR_UNDECLARED_ENTITY; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4561 | } |
| 4562 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4563 | |
| 4564 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4565 | * [ WFC: Parsed Entity ] |
| 4566 | * An entity reference must not contain the name of an |
| 4567 | * unparsed entity |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4568 | */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4569 | else if (ent->type == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { |
| 4570 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4571 | ctxt->sax->error(ctxt->userData, |
| 4572 | "Entity reference to unparsed entity %s\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4573 | ctxt->errNo = XML_ERR_UNPARSED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4574 | ctxt->wellFormed = 0; |
| 4575 | } |
| 4576 | |
| 4577 | /* |
| 4578 | * [ WFC: No External Entity References ] |
| 4579 | * Attribute values cannot contain direct or indirect |
| 4580 | * entity references to external entities. |
| 4581 | */ |
| 4582 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && |
| 4583 | (ent->type == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { |
| 4584 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4585 | ctxt->sax->error(ctxt->userData, |
| 4586 | "Attribute references external entity '%s'\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4587 | ctxt->errNo = XML_ERR_ENTITY_IS_EXTERNAL; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4588 | ctxt->wellFormed = 0; |
| 4589 | } |
| 4590 | /* |
| 4591 | * [ WFC: No < in Attribute Values ] |
| 4592 | * The replacement text of any entity referred to directly or |
| 4593 | * indirectly in an attribute value (other than "<") must |
| 4594 | * not contain a <. |
| 4595 | */ |
| 4596 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4597 | (ent != NULL) && |
| 4598 | (xmlStrcmp(ent->name, BAD_CAST "lt")) && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4599 | (ent->content != NULL) && |
| 4600 | (xmlStrchr(ent->content, '<'))) { |
| 4601 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4602 | ctxt->sax->error(ctxt->userData, |
| 4603 | "'<' in entity '%s' is not allowed in attributes values\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4604 | ctxt->errNo = XML_ERR_LT_IN_ATTRIBUTE; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4605 | ctxt->wellFormed = 0; |
| 4606 | } |
| 4607 | |
| 4608 | /* |
| 4609 | * Internal check, no parameter entities here ... |
| 4610 | */ |
| 4611 | else { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4612 | switch (ent->type) { |
| 4613 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 4614 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 4615 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4616 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4617 | "Attempt to reference the parameter entity '%s'\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4618 | ctxt->errNo = XML_ERR_ENTITY_IS_PARAMETER; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4619 | ctxt->wellFormed = 0; |
| 4620 | break; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4625 | * [ WFC: No Recursion ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4626 | * TODO A parsed entity must not contain a recursive reference |
| 4627 | * to itself, either directly or indirectly. |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4628 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4629 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4630 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4631 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4632 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4633 | "xmlParseEntityRef: expecting ';'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4634 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4635 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4636 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4637 | xmlFree(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4638 | } |
| 4639 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4640 | return(ent); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4643 | /** |
| 4644 | * xmlParsePEReference: |
| 4645 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4646 | * |
| 4647 | * parse PEReference declarations |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4648 | * The entity content is handled directly by pushing it's content as |
| 4649 | * a new input stream. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4650 | * |
| 4651 | * [69] PEReference ::= '%' Name ';' |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4652 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4653 | * [ WFC: No Recursion ] |
| 4654 | * TODO A parsed entity must not contain a recursive |
| 4655 | * reference to itself, either directly or indirectly. |
| 4656 | * |
| 4657 | * [ WFC: Entity Declared ] |
| 4658 | * In a document without any DTD, a document with only an internal DTD |
| 4659 | * subset which contains no parameter entity references, or a document |
| 4660 | * with "standalone='yes'", ... ... The declaration of a parameter |
| 4661 | * entity must precede any reference to it... |
| 4662 | * |
| 4663 | * [ VC: Entity Declared ] |
| 4664 | * In a document with an external subset or external parameter entities |
| 4665 | * with "standalone='no'", ... ... The declaration of a parameter entity |
| 4666 | * must precede any reference to it... |
| 4667 | * |
| 4668 | * [ WFC: In DTD ] |
| 4669 | * Parameter-entity references may only appear in the DTD. |
| 4670 | * NOTE: misleading but this is handled. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4671 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4672 | void |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4673 | xmlParsePEReference(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4674 | xmlChar *name; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4675 | xmlEntityPtr entity = NULL; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 4676 | xmlParserInputPtr input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4677 | |
| 4678 | if (CUR == '%') { |
| 4679 | NEXT; |
| 4680 | name = xmlParseName(ctxt); |
| 4681 | if (name == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4682 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4683 | ctxt->sax->error(ctxt->userData, |
| 4684 | "xmlParsePEReference: no name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4685 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4686 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4687 | } else { |
| 4688 | if (CUR == ';') { |
| 4689 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4690 | if ((ctxt->sax != NULL) && |
| 4691 | (ctxt->sax->getParameterEntity != NULL)) |
| 4692 | entity = ctxt->sax->getParameterEntity(ctxt->userData, |
| 4693 | name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4694 | if (entity == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4695 | /* |
| 4696 | * [ WFC: Entity Declared ] |
| 4697 | * In a document without any DTD, a document with only an |
| 4698 | * internal DTD subset which contains no parameter entity |
| 4699 | * references, or a document with "standalone='yes'", ... |
| 4700 | * ... The declaration of a parameter entity must precede |
| 4701 | * any reference to it... |
| 4702 | */ |
| 4703 | if ((ctxt->standalone == 1) || |
| 4704 | ((ctxt->hasExternalSubset == 0) && |
| 4705 | (ctxt->hasPErefs == 0))) { |
| 4706 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4707 | ctxt->sax->error(ctxt->userData, |
| 4708 | "PEReference: %%%s; not found\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4709 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4710 | ctxt->wellFormed = 0; |
| 4711 | } else { |
| 4712 | /* |
| 4713 | * [ VC: Entity Declared ] |
| 4714 | * In a document with an external subset or external |
| 4715 | * parameter entities with "standalone='no'", ... |
| 4716 | * ... The declaration of a parameter entity must precede |
| 4717 | * any reference to it... |
| 4718 | */ |
| 4719 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 4720 | ctxt->sax->warning(ctxt->userData, |
| 4721 | "PEReference: %%%s; not found\n", name); |
| 4722 | ctxt->valid = 0; |
| 4723 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 4724 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4725 | /* |
| 4726 | * Internal checking in case the entity quest barfed |
| 4727 | */ |
| 4728 | if ((entity->type != XML_INTERNAL_PARAMETER_ENTITY) && |
| 4729 | (entity->type != XML_EXTERNAL_PARAMETER_ENTITY)) { |
| 4730 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 4731 | ctxt->sax->warning(ctxt->userData, |
| 4732 | "Internal: %%%s; is not a parameter entity\n", name); |
| 4733 | } else { |
| 4734 | input = xmlNewEntityInputStream(ctxt, entity); |
| 4735 | xmlPushInput(ctxt, input); |
| 4736 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4737 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4738 | ctxt->hasPErefs = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4739 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4740 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4741 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4742 | "xmlParsePEReference: expecting ';'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4743 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4744 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4745 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4746 | xmlFree(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4747 | } |
| 4748 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4751 | /** |
| 4752 | * xmlParseDocTypeDecl : |
| 4753 | * @ctxt: an XML parser context |
| 4754 | * |
| 4755 | * parse a DOCTYPE declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4756 | * |
| 4757 | * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? |
| 4758 | * ('[' (markupdecl | PEReference | S)* ']' S?)? '>' |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4759 | * |
| 4760 | * [ VC: Root Element Type ] |
| 4761 | * The Name in the document type declaration must match the element |
| 4762 | * type of the root element. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4763 | */ |
| 4764 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4765 | void |
| 4766 | xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4767 | xmlChar *name; |
| 4768 | xmlChar *ExternalID = NULL; |
| 4769 | xmlChar *URI = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4770 | |
| 4771 | /* |
| 4772 | * We know that '<!DOCTYPE' has been detected. |
| 4773 | */ |
| 4774 | SKIP(9); |
| 4775 | |
| 4776 | SKIP_BLANKS; |
| 4777 | |
| 4778 | /* |
| 4779 | * Parse the DOCTYPE name. |
| 4780 | */ |
| 4781 | name = xmlParseName(ctxt); |
| 4782 | if (name == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4783 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4784 | ctxt->sax->error(ctxt->userData, |
| 4785 | "xmlParseDocTypeDecl : no DOCTYPE name !\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4786 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4787 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | SKIP_BLANKS; |
| 4791 | |
| 4792 | /* |
| 4793 | * Check for SystemID and ExternalID |
| 4794 | */ |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4795 | URI = xmlParseExternalID(ctxt, &ExternalID, 1); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4796 | |
| 4797 | if ((URI != NULL) || (ExternalID != NULL)) { |
| 4798 | ctxt->hasExternalSubset = 1; |
| 4799 | } |
| 4800 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4801 | SKIP_BLANKS; |
| 4802 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4803 | /* |
| 4804 | * NOTE: the SAX callback may try to fetch the external subset |
| 4805 | * entity and fill it up ! |
| 4806 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4807 | if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4808 | ctxt->sax->internalSubset(ctxt->userData, name, ExternalID, URI); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4809 | |
| 4810 | /* |
| 4811 | * Is there any DTD definition ? |
| 4812 | */ |
| 4813 | if (CUR == '[') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4814 | ctxt->instate = XML_PARSER_DTD; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4815 | NEXT; |
| 4816 | /* |
| 4817 | * Parse the succession of Markup declarations and |
| 4818 | * PEReferences. |
| 4819 | * Subsequence (markupdecl | PEReference | S)* |
| 4820 | */ |
| 4821 | while (CUR != ']') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4822 | const xmlChar *check = CUR_PTR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4823 | int cons = ctxt->input->consumed; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4824 | |
| 4825 | SKIP_BLANKS; |
| 4826 | xmlParseMarkupDecl(ctxt); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 4827 | xmlParsePEReference(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4828 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4829 | /* |
| 4830 | * Pop-up of finished entities. |
| 4831 | */ |
| 4832 | while ((CUR == 0) && (ctxt->inputNr > 1)) |
| 4833 | xmlPopInput(ctxt); |
| 4834 | |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 4835 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4836 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4837 | ctxt->sax->error(ctxt->userData, |
| 4838 | "xmlParseDocTypeDecl: error detected in Markup declaration\n"); |
| 4839 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4840 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4841 | break; |
| 4842 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4843 | } |
| 4844 | if (CUR == ']') NEXT; |
| 4845 | } |
| 4846 | |
| 4847 | /* |
| 4848 | * We should be at the end of the DOCTYPE declaration. |
| 4849 | */ |
| 4850 | if (CUR != '>') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4851 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4852 | ctxt->sax->error(ctxt->userData, "DOCTYPE unproperly terminated\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4853 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4854 | ctxt->errNo = XML_ERR_DOCTYPE_NOT_FINISHED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4855 | } |
| 4856 | NEXT; |
| 4857 | |
| 4858 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4859 | * Cleanup |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4860 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4861 | if (URI != NULL) xmlFree(URI); |
| 4862 | if (ExternalID != NULL) xmlFree(ExternalID); |
| 4863 | if (name != NULL) xmlFree(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4864 | } |
| 4865 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4866 | /** |
| 4867 | * xmlParseAttribute: |
| 4868 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4869 | * @value: a xmlChar ** used to store the value of the attribute |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4870 | * |
| 4871 | * parse an attribute |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4872 | * |
| 4873 | * [41] Attribute ::= Name Eq AttValue |
| 4874 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4875 | * [ WFC: No External Entity References ] |
| 4876 | * Attribute values cannot contain direct or indirect entity references |
| 4877 | * to external entities. |
| 4878 | * |
| 4879 | * [ WFC: No < in Attribute Values ] |
| 4880 | * The replacement text of any entity referred to directly or indirectly in |
| 4881 | * an attribute value (other than "<") must not contain a <. |
| 4882 | * |
| 4883 | * [ VC: Attribute Value Type ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4884 | * The attribute must have been declared; the value must be of the type |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4885 | * declared for it. |
| 4886 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4887 | * [25] Eq ::= S? '=' S? |
| 4888 | * |
| 4889 | * With namespace: |
| 4890 | * |
| 4891 | * [NS 11] Attribute ::= QName Eq AttValue |
| 4892 | * |
| 4893 | * Also the case QName == xmlns:??? is handled independently as a namespace |
| 4894 | * definition. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4895 | * |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4896 | * Returns the attribute name, and the value in *value. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4897 | */ |
| 4898 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4899 | xmlChar * |
| 4900 | xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) { |
| 4901 | xmlChar *name, *val; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4902 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4903 | *value = NULL; |
| 4904 | name = xmlParseName(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4905 | if (name == NULL) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4906 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4907 | ctxt->sax->error(ctxt->userData, "error parsing attribute name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4908 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4909 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 4910 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | /* |
| 4914 | * read the value |
| 4915 | */ |
| 4916 | SKIP_BLANKS; |
| 4917 | if (CUR == '=') { |
| 4918 | NEXT; |
| 4919 | SKIP_BLANKS; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4920 | val = xmlParseAttValue(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4921 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4922 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4923 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4924 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4925 | "Specification mandate value for attribute %s\n", name); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4926 | ctxt->errNo = XML_ERR_ATTRIBUTE_WITHOUT_VALUE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4927 | ctxt->wellFormed = 0; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 4928 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4931 | *value = val; |
| 4932 | return(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4935 | /** |
| 4936 | * xmlParseStartTag: |
| 4937 | * @ctxt: an XML parser context |
| 4938 | * |
| 4939 | * parse a start of tag either for rule element or |
| 4940 | * EmptyElement. In both case we don't parse the tag closing chars. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4941 | * |
| 4942 | * [40] STag ::= '<' Name (S Attribute)* S? '>' |
| 4943 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4944 | * [ WFC: Unique Att Spec ] |
| 4945 | * No attribute name may appear more than once in the same start-tag or |
| 4946 | * empty-element tag. |
| 4947 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4948 | * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' |
| 4949 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4950 | * [ WFC: Unique Att Spec ] |
| 4951 | * No attribute name may appear more than once in the same start-tag or |
| 4952 | * empty-element tag. |
| 4953 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4954 | * With namespace: |
| 4955 | * |
| 4956 | * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' |
| 4957 | * |
| 4958 | * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 4959 | * |
| 4960 | * Returns the element name parsed |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4961 | */ |
| 4962 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4963 | xmlChar * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4964 | xmlParseStartTag(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4965 | xmlChar *name; |
| 4966 | xmlChar *attname; |
| 4967 | xmlChar *attvalue; |
| 4968 | const xmlChar **atts = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4969 | int nbatts = 0; |
| 4970 | int maxatts = 0; |
| 4971 | int i; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4972 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 4973 | if (CUR != '<') return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4974 | NEXT; |
| 4975 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4976 | name = xmlParseName(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4977 | if (name == NULL) { |
| 4978 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4979 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4980 | "xmlParseStartTag: invalid element name\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4981 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4982 | ctxt->wellFormed = 0; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 4983 | return(NULL); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4984 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4985 | |
| 4986 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4987 | * Now parse the attributes, it ends up with the ending |
| 4988 | * |
| 4989 | * (S Attribute)* S? |
| 4990 | */ |
| 4991 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 4992 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4993 | while ((IS_CHAR(CUR)) && |
| 4994 | (CUR != '>') && |
| 4995 | ((CUR != '/') || (NXT(1) != '>'))) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4996 | const xmlChar *q = CUR_PTR; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 4997 | int cons = ctxt->input->consumed; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4998 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4999 | attname = xmlParseAttribute(ctxt, &attvalue); |
| 5000 | if ((attname != NULL) && (attvalue != NULL)) { |
| 5001 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5002 | * [ WFC: Unique Att Spec ] |
| 5003 | * No attribute name may appear more than once in the same |
| 5004 | * start-tag or empty-element tag. |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5005 | */ |
| 5006 | for (i = 0; i < nbatts;i += 2) { |
| 5007 | if (!xmlStrcmp(atts[i], attname)) { |
| 5008 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5009 | ctxt->sax->error(ctxt->userData, |
| 5010 | "Attribute %s redefined\n", |
| 5011 | attname); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5012 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5013 | ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5014 | xmlFree(attname); |
| 5015 | xmlFree(attvalue); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5016 | goto failed; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5017 | } |
| 5018 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5019 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5020 | /* |
| 5021 | * Add the pair to atts |
| 5022 | */ |
| 5023 | if (atts == NULL) { |
| 5024 | maxatts = 10; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5025 | atts = (const xmlChar **) xmlMalloc(maxatts * sizeof(xmlChar *)); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5026 | if (atts == NULL) { |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 5027 | fprintf(stderr, "malloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5028 | maxatts * (long)sizeof(xmlChar *)); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5029 | return(NULL); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5030 | } |
| 5031 | } else if (nbatts + 2 < maxatts) { |
| 5032 | maxatts *= 2; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5033 | atts = (const xmlChar **) xmlRealloc(atts, |
| 5034 | maxatts * sizeof(xmlChar *)); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5035 | if (atts == NULL) { |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 5036 | fprintf(stderr, "realloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5037 | maxatts * (long)sizeof(xmlChar *)); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5038 | return(NULL); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5039 | } |
| 5040 | } |
| 5041 | atts[nbatts++] = attname; |
| 5042 | atts[nbatts++] = attvalue; |
| 5043 | atts[nbatts] = NULL; |
| 5044 | atts[nbatts + 1] = NULL; |
| 5045 | } |
| 5046 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5047 | failed: |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5048 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5049 | if ((cons == ctxt->input->consumed) && (q == CUR_PTR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5050 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5051 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5052 | "xmlParseStartTag: problem parsing attributes\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5053 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5054 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5055 | break; |
| 5056 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5057 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5061 | * SAX: Start of Element ! |
| 5062 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5063 | if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5064 | ctxt->sax->startElement(ctxt->userData, name, atts); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5065 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5066 | if (atts != NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5067 | for (i = 0;i < nbatts;i++) xmlFree((xmlChar *) atts[i]); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5068 | xmlFree(atts); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5069 | } |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5070 | return(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5073 | /** |
| 5074 | * xmlParseEndTag: |
| 5075 | * @ctxt: an XML parser context |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5076 | * @tagname: the tag name as parsed in the opening tag. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5077 | * |
| 5078 | * parse an end of tag |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5079 | * |
| 5080 | * [42] ETag ::= '</' Name S? '>' |
| 5081 | * |
| 5082 | * With namespace |
| 5083 | * |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5084 | * [NS 9] ETag ::= '</' QName S? '>' |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5085 | */ |
| 5086 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5087 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5088 | xmlParseEndTag(xmlParserCtxtPtr ctxt, xmlChar *tagname) { |
| 5089 | xmlChar *name; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5090 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5091 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5092 | if ((CUR != '<') || (NXT(1) != '/')) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5093 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5094 | ctxt->sax->error(ctxt->userData, "xmlParseEndTag: '</' not found\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5095 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5096 | ctxt->errNo = XML_ERR_LTSLASH_REQUIRED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5097 | return; |
| 5098 | } |
| 5099 | SKIP(2); |
| 5100 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5101 | name = xmlParseName(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5102 | |
| 5103 | /* |
| 5104 | * We should definitely be at the ending "S? '>'" part |
| 5105 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5106 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5107 | SKIP_BLANKS; |
| 5108 | if ((!IS_CHAR(CUR)) || (CUR != '>')) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5109 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5110 | ctxt->sax->error(ctxt->userData, "End tag : expected '>'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5111 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5112 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5113 | } else |
| 5114 | NEXT; |
| 5115 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5116 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5117 | * [ WFC: Element Type Match ] |
| 5118 | * The Name in an element's end-tag must match the element type in the |
| 5119 | * start-tag. |
| 5120 | * |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5121 | */ |
| 5122 | if (xmlStrcmp(name, tagname)) { |
| 5123 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5124 | ctxt->sax->error(ctxt->userData, |
| 5125 | "Opening and ending tag mismatch: %s and %s\n", tagname, name); |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5126 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5127 | ctxt->errNo = XML_ERR_TAG_NAME_MISMATCH; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5128 | ctxt->wellFormed = 0; |
| 5129 | } |
| 5130 | |
| 5131 | /* |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5132 | * SAX: End of Tag |
| 5133 | */ |
| 5134 | if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5135 | ctxt->sax->endElement(ctxt->userData, name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5136 | |
| 5137 | if (name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5138 | xmlFree(name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5139 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5140 | return; |
| 5141 | } |
| 5142 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5143 | /** |
| 5144 | * xmlParseCDSect: |
| 5145 | * @ctxt: an XML parser context |
| 5146 | * |
| 5147 | * Parse escaped pure raw content. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5148 | * |
| 5149 | * [18] CDSect ::= CDStart CData CDEnd |
| 5150 | * |
| 5151 | * [19] CDStart ::= '<![CDATA[' |
| 5152 | * |
| 5153 | * [20] Data ::= (Char* - (Char* ']]>' Char*)) |
| 5154 | * |
| 5155 | * [21] CDEnd ::= ']]>' |
| 5156 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5157 | void |
| 5158 | xmlParseCDSect(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5159 | const xmlChar *base; |
| 5160 | xmlChar r, s; |
| 5161 | xmlChar cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5162 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5163 | if ((NXT(0) == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5164 | (NXT(2) == '[') && (NXT(3) == 'C') && |
| 5165 | (NXT(4) == 'D') && (NXT(5) == 'A') && |
| 5166 | (NXT(6) == 'T') && (NXT(7) == 'A') && |
| 5167 | (NXT(8) == '[')) { |
| 5168 | SKIP(9); |
| 5169 | } else |
| 5170 | return; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5171 | |
| 5172 | ctxt->instate = XML_PARSER_CDATA_SECTION; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5173 | base = CUR_PTR; |
| 5174 | if (!IS_CHAR(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5175 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5176 | ctxt->sax->error(ctxt->userData, |
| 5177 | "CData section not finished\n%.50s\n", base); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5178 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5179 | ctxt->errNo = XML_ERR_CDATA_NOT_FINISHED; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5180 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5181 | return; |
| 5182 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5183 | r = CUR; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5184 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5185 | if (!IS_CHAR(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5186 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5187 | ctxt->sax->error(ctxt->userData, |
| 5188 | "CData section not finished\n%.50s\n", base); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5189 | ctxt->errNo = XML_ERR_CDATA_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5190 | ctxt->wellFormed = 0; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5191 | ctxt->instate = XML_PARSER_CONTENT; |
| 5192 | return; |
| 5193 | } |
| 5194 | s = CUR; |
| 5195 | NEXT; |
| 5196 | cur = CUR; |
| 5197 | while (IS_CHAR(cur) && |
| 5198 | ((r != ']') || (s != ']') || (cur != '>'))) { |
| 5199 | r = s; |
| 5200 | s = cur; |
| 5201 | NEXT; |
| 5202 | cur = CUR; |
| 5203 | } |
| 5204 | ctxt->instate = XML_PARSER_CONTENT; |
| 5205 | if (!IS_CHAR(CUR)) { |
| 5206 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5207 | ctxt->sax->error(ctxt->userData, |
| 5208 | "CData section not finished\n%.50s\n", base); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5209 | ctxt->errNo = XML_ERR_CDATA_NOT_FINISHED; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5210 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5211 | return; |
| 5212 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5213 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5214 | |
| 5215 | /* |
| 5216 | * Ok the segment [base CUR_PTR] is to be consumed as chars. |
| 5217 | */ |
| 5218 | if (ctxt->sax != NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5219 | if (ctxt->sax->cdataBlock != NULL) |
| 5220 | ctxt->sax->cdataBlock(ctxt->userData, base, (CUR_PTR - base) - 3); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5224 | /** |
| 5225 | * xmlParseContent: |
| 5226 | * @ctxt: an XML parser context |
| 5227 | * |
| 5228 | * Parse a content: |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5229 | * |
| 5230 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* |
| 5231 | */ |
| 5232 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5233 | void |
| 5234 | xmlParseContent(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5235 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5236 | while ((CUR != '<') || (NXT(1) != '/')) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5237 | const xmlChar *test = CUR_PTR; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5238 | int cons = ctxt->input->consumed; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5239 | xmlChar tok = ctxt->token; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5240 | |
| 5241 | /* |
| 5242 | * First case : a Processing Instruction. |
| 5243 | */ |
| 5244 | if ((CUR == '<') && (NXT(1) == '?')) { |
| 5245 | xmlParsePI(ctxt); |
| 5246 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5247 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5248 | /* |
| 5249 | * Second case : a CDSection |
| 5250 | */ |
| 5251 | else if ((CUR == '<') && (NXT(1) == '!') && |
| 5252 | (NXT(2) == '[') && (NXT(3) == 'C') && |
| 5253 | (NXT(4) == 'D') && (NXT(5) == 'A') && |
| 5254 | (NXT(6) == 'T') && (NXT(7) == 'A') && |
| 5255 | (NXT(8) == '[')) { |
| 5256 | xmlParseCDSect(ctxt); |
| 5257 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5258 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5259 | /* |
| 5260 | * Third case : a comment |
| 5261 | */ |
| 5262 | else if ((CUR == '<') && (NXT(1) == '!') && |
| 5263 | (NXT(2) == '-') && (NXT(3) == '-')) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5264 | xmlParseComment(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5265 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5266 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5267 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5268 | /* |
| 5269 | * Fourth case : a sub-element. |
| 5270 | */ |
| 5271 | else if (CUR == '<') { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5272 | xmlParseElement(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5273 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5274 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5275 | /* |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 5276 | * Fifth case : a reference. If if has not been resolved, |
| 5277 | * parsing returns it's Name, create the node |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5278 | */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5279 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5280 | else if (CUR == '&') { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5281 | xmlParseReference(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5282 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5283 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5284 | /* |
| 5285 | * Last case, text. Note that References are handled directly. |
| 5286 | */ |
| 5287 | else { |
| 5288 | xmlParseCharData(ctxt, 0); |
| 5289 | } |
| 5290 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5291 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5292 | /* |
| 5293 | * Pop-up of finished entities. |
| 5294 | */ |
Daniel Veillard | bc50b59 | 1999-03-01 12:28:53 +0000 | [diff] [blame] | 5295 | while ((CUR == 0) && (ctxt->inputNr > 1)) |
| 5296 | xmlPopInput(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5297 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5298 | if ((cons == ctxt->input->consumed) && (test == CUR_PTR) && |
| 5299 | (tok == ctxt->token)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5300 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5301 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5302 | "detected an error in element content\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5303 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5304 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5305 | break; |
| 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5310 | /** |
| 5311 | * xmlParseElement: |
| 5312 | * @ctxt: an XML parser context |
| 5313 | * |
| 5314 | * parse an XML element, this is highly recursive |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5315 | * |
| 5316 | * [39] element ::= EmptyElemTag | STag content ETag |
| 5317 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5318 | * [ WFC: Element Type Match ] |
| 5319 | * The Name in an element's end-tag must match the element type in the |
| 5320 | * start-tag. |
| 5321 | * |
| 5322 | * [ VC: Element Valid ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5323 | * An element is valid if there is a declaration matching elementdecl |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5324 | * where the Name matches the element type and one of the following holds: |
| 5325 | * - The declaration matches EMPTY and the element has no content. |
| 5326 | * - The declaration matches children and the sequence of child elements |
| 5327 | * belongs to the language generated by the regular expression in the |
| 5328 | * content model, with optional white space (characters matching the |
| 5329 | * nonterminal S) between each pair of child elements. |
| 5330 | * - The declaration matches Mixed and the content consists of character |
| 5331 | * data and child elements whose types match names in the content model. |
| 5332 | * - The declaration matches ANY, and the types of any child elements have |
| 5333 | * been declared. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5334 | */ |
| 5335 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5336 | void |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5337 | xmlParseElement(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5338 | const xmlChar *openTag = CUR_PTR; |
| 5339 | xmlChar *name; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5340 | xmlParserNodeInfo node_info; |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 5341 | xmlNodePtr ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5342 | |
| 5343 | /* Capture start position */ |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 5344 | if (ctxt->record_info) { |
| 5345 | node_info.begin_pos = ctxt->input->consumed + |
| 5346 | (CUR_PTR - ctxt->input->base); |
| 5347 | node_info.begin_line = ctxt->input->line; |
| 5348 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5349 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5350 | name = xmlParseStartTag(ctxt); |
| 5351 | if (name == NULL) { |
| 5352 | return; |
| 5353 | } |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 5354 | ret = ctxt->node; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5355 | |
| 5356 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5357 | * [ VC: Root Element Type ] |
| 5358 | * The Name in the document type declaration must match the element |
| 5359 | * type of the root element. |
| 5360 | */ |
| 5361 | if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && |
| 5362 | ctxt->node && (ctxt->node == ctxt->myDoc->root)) |
| 5363 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); |
| 5364 | |
| 5365 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5366 | * Check for an Empty Element. |
| 5367 | */ |
| 5368 | if ((CUR == '/') && (NXT(1) == '>')) { |
| 5369 | SKIP(2); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5370 | if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5371 | ctxt->sax->endElement(ctxt->userData, name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5372 | xmlFree(name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5373 | return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5374 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5375 | if (CUR == '>') { |
| 5376 | NEXT; |
| 5377 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5378 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5379 | ctxt->sax->error(ctxt->userData, |
| 5380 | "Couldn't find end of Start Tag\n%.30s\n", |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 5381 | openTag); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5382 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5383 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5384 | |
| 5385 | /* |
| 5386 | * end of parsing of this node. |
| 5387 | */ |
| 5388 | nodePop(ctxt); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5389 | xmlFree(name); |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 5390 | |
| 5391 | /* |
| 5392 | * Capture end position and add node |
| 5393 | */ |
| 5394 | if ( ret != NULL && ctxt->record_info ) { |
| 5395 | node_info.end_pos = ctxt->input->consumed + |
| 5396 | (CUR_PTR - ctxt->input->base); |
| 5397 | node_info.end_line = ctxt->input->line; |
| 5398 | node_info.node = ret; |
| 5399 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 5400 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5401 | return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | /* |
| 5405 | * Parse the content of the element: |
| 5406 | */ |
| 5407 | xmlParseContent(ctxt); |
| 5408 | if (!IS_CHAR(CUR)) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5409 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5410 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 5411 | "Premature end of data in tag %.30s\n", openTag); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5412 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5413 | ctxt->errNo = XML_ERR_TAG_NOT_FINISED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5414 | |
| 5415 | /* |
| 5416 | * end of parsing of this node. |
| 5417 | */ |
| 5418 | nodePop(ctxt); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5419 | xmlFree(name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5420 | return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | /* |
| 5424 | * parse the end of tag: '</' should be here. |
| 5425 | */ |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5426 | xmlParseEndTag(ctxt, name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5427 | xmlFree(name); |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 5428 | |
| 5429 | /* |
| 5430 | * Capture end position and add node |
| 5431 | */ |
| 5432 | if ( ret != NULL && ctxt->record_info ) { |
| 5433 | node_info.end_pos = ctxt->input->consumed + |
| 5434 | (CUR_PTR - ctxt->input->base); |
| 5435 | node_info.end_line = ctxt->input->line; |
| 5436 | node_info.node = ret; |
| 5437 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 5438 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5439 | } |
| 5440 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5441 | /** |
| 5442 | * xmlParseVersionNum: |
| 5443 | * @ctxt: an XML parser context |
| 5444 | * |
| 5445 | * parse the XML version value. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5446 | * |
| 5447 | * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5448 | * |
| 5449 | * Returns the string giving the XML version number, or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5450 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5451 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5452 | xmlParseVersionNum(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5453 | const xmlChar *q = CUR_PTR; |
| 5454 | xmlChar *ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5455 | |
| 5456 | while (IS_CHAR(CUR) && |
| 5457 | (((CUR >= 'a') && (CUR <= 'z')) || |
| 5458 | ((CUR >= 'A') && (CUR <= 'Z')) || |
| 5459 | ((CUR >= '0') && (CUR <= '9')) || |
| 5460 | (CUR == '_') || (CUR == '.') || |
| 5461 | (CUR == ':') || (CUR == '-'))) NEXT; |
| 5462 | ret = xmlStrndup(q, CUR_PTR - q); |
| 5463 | return(ret); |
| 5464 | } |
| 5465 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5466 | /** |
| 5467 | * xmlParseVersionInfo: |
| 5468 | * @ctxt: an XML parser context |
| 5469 | * |
| 5470 | * parse the XML version. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5471 | * |
| 5472 | * [24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ") |
| 5473 | * |
| 5474 | * [25] Eq ::= S? '=' S? |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5475 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5476 | * Returns the version string, e.g. "1.0" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5477 | */ |
| 5478 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5479 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5480 | xmlParseVersionInfo(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5481 | xmlChar *version = NULL; |
| 5482 | const xmlChar *q; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5483 | |
| 5484 | if ((CUR == 'v') && (NXT(1) == 'e') && |
| 5485 | (NXT(2) == 'r') && (NXT(3) == 's') && |
| 5486 | (NXT(4) == 'i') && (NXT(5) == 'o') && |
| 5487 | (NXT(6) == 'n')) { |
| 5488 | SKIP(7); |
| 5489 | SKIP_BLANKS; |
| 5490 | if (CUR != '=') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5491 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5492 | ctxt->sax->error(ctxt->userData, |
| 5493 | "xmlParseVersionInfo : expected '='\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5494 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5495 | ctxt->errNo = XML_ERR_EQUAL_REQUIRED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5496 | return(NULL); |
| 5497 | } |
| 5498 | NEXT; |
| 5499 | SKIP_BLANKS; |
| 5500 | if (CUR == '"') { |
| 5501 | NEXT; |
| 5502 | q = CUR_PTR; |
| 5503 | version = xmlParseVersionNum(ctxt); |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5504 | if (CUR != '"') { |
| 5505 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5506 | ctxt->sax->error(ctxt->userData, |
| 5507 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5508 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5509 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5510 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5511 | NEXT; |
| 5512 | } else if (CUR == '\''){ |
| 5513 | NEXT; |
| 5514 | q = CUR_PTR; |
| 5515 | version = xmlParseVersionNum(ctxt); |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5516 | if (CUR != '\'') { |
| 5517 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5518 | ctxt->sax->error(ctxt->userData, |
| 5519 | "String not closed\n%.50s\n", q); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5520 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5521 | ctxt->wellFormed = 0; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5522 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5523 | NEXT; |
| 5524 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5525 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5526 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5527 | "xmlParseVersionInfo : expected ' or \"\n"); |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5528 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5529 | ctxt->errNo = XML_ERR_STRING_NOT_STARTED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5530 | } |
| 5531 | } |
| 5532 | return(version); |
| 5533 | } |
| 5534 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5535 | /** |
| 5536 | * xmlParseEncName: |
| 5537 | * @ctxt: an XML parser context |
| 5538 | * |
| 5539 | * parse the XML encoding name |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5540 | * |
| 5541 | * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5542 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5543 | * Returns the encoding name value or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5544 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5545 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5546 | xmlParseEncName(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5547 | const xmlChar *q = CUR_PTR; |
| 5548 | xmlChar *ret = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5549 | |
| 5550 | if (((CUR >= 'a') && (CUR <= 'z')) || |
| 5551 | ((CUR >= 'A') && (CUR <= 'Z'))) { |
| 5552 | NEXT; |
| 5553 | while (IS_CHAR(CUR) && |
| 5554 | (((CUR >= 'a') && (CUR <= 'z')) || |
| 5555 | ((CUR >= 'A') && (CUR <= 'Z')) || |
| 5556 | ((CUR >= '0') && (CUR <= '9')) || |
| 5557 | (CUR == '-'))) NEXT; |
| 5558 | ret = xmlStrndup(q, CUR_PTR - q); |
| 5559 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5560 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5561 | ctxt->sax->error(ctxt->userData, "Invalid XML encoding name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5562 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5563 | ctxt->errNo = XML_ERR_ENCODING_NAME; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5564 | } |
| 5565 | return(ret); |
| 5566 | } |
| 5567 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5568 | /** |
| 5569 | * xmlParseEncodingDecl: |
| 5570 | * @ctxt: an XML parser context |
| 5571 | * |
| 5572 | * parse the XML encoding declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5573 | * |
| 5574 | * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'") |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5575 | * |
| 5576 | * TODO: this should setup the conversion filters. |
| 5577 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5578 | * Returns the encoding value or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5579 | */ |
| 5580 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5581 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5582 | xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5583 | xmlChar *encoding = NULL; |
| 5584 | const xmlChar *q; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5585 | |
| 5586 | SKIP_BLANKS; |
| 5587 | if ((CUR == 'e') && (NXT(1) == 'n') && |
| 5588 | (NXT(2) == 'c') && (NXT(3) == 'o') && |
| 5589 | (NXT(4) == 'd') && (NXT(5) == 'i') && |
| 5590 | (NXT(6) == 'n') && (NXT(7) == 'g')) { |
| 5591 | SKIP(8); |
| 5592 | SKIP_BLANKS; |
| 5593 | if (CUR != '=') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5594 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5595 | ctxt->sax->error(ctxt->userData, |
| 5596 | "xmlParseEncodingDecl : expected '='\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5597 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5598 | ctxt->errNo = XML_ERR_EQUAL_REQUIRED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5599 | return(NULL); |
| 5600 | } |
| 5601 | NEXT; |
| 5602 | SKIP_BLANKS; |
| 5603 | if (CUR == '"') { |
| 5604 | NEXT; |
| 5605 | q = CUR_PTR; |
| 5606 | encoding = xmlParseEncName(ctxt); |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5607 | if (CUR != '"') { |
| 5608 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5609 | ctxt->sax->error(ctxt->userData, |
| 5610 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5611 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5612 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5613 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5614 | NEXT; |
| 5615 | } else if (CUR == '\''){ |
| 5616 | NEXT; |
| 5617 | q = CUR_PTR; |
| 5618 | encoding = xmlParseEncName(ctxt); |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5619 | if (CUR != '\'') { |
| 5620 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5621 | ctxt->sax->error(ctxt->userData, |
| 5622 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5623 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5624 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5625 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5626 | NEXT; |
| 5627 | } else if (CUR == '"'){ |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5628 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5629 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5630 | "xmlParseEncodingDecl : expected ' or \"\n"); |
| 5631 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5632 | ctxt->errNo = XML_ERR_STRING_NOT_STARTED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5633 | } |
| 5634 | } |
| 5635 | return(encoding); |
| 5636 | } |
| 5637 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5638 | /** |
| 5639 | * xmlParseSDDecl: |
| 5640 | * @ctxt: an XML parser context |
| 5641 | * |
| 5642 | * parse the XML standalone declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5643 | * |
| 5644 | * [32] SDDecl ::= S 'standalone' Eq |
| 5645 | * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5646 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5647 | * [ VC: Standalone Document Declaration ] |
| 5648 | * TODO The standalone document declaration must have the value "no" |
| 5649 | * if any external markup declarations contain declarations of: |
| 5650 | * - attributes with default values, if elements to which these |
| 5651 | * attributes apply appear in the document without specifications |
| 5652 | * of values for these attributes, or |
| 5653 | * - entities (other than amp, lt, gt, apos, quot), if references |
| 5654 | * to those entities appear in the document, or |
| 5655 | * - attributes with values subject to normalization, where the |
| 5656 | * attribute appears in the document with a value which will change |
| 5657 | * as a result of normalization, or |
| 5658 | * - element types with element content, if white space occurs directly |
| 5659 | * within any instance of those types. |
| 5660 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5661 | * Returns 1 if standalone, 0 otherwise |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5662 | */ |
| 5663 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5664 | int |
| 5665 | xmlParseSDDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5666 | int standalone = -1; |
| 5667 | |
| 5668 | SKIP_BLANKS; |
| 5669 | if ((CUR == 's') && (NXT(1) == 't') && |
| 5670 | (NXT(2) == 'a') && (NXT(3) == 'n') && |
| 5671 | (NXT(4) == 'd') && (NXT(5) == 'a') && |
| 5672 | (NXT(6) == 'l') && (NXT(7) == 'o') && |
| 5673 | (NXT(8) == 'n') && (NXT(9) == 'e')) { |
| 5674 | SKIP(10); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5675 | SKIP_BLANKS; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5676 | if (CUR != '=') { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5677 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5678 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5679 | "XML standalone declaration : expected '='\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5680 | ctxt->errNo = XML_ERR_EQUAL_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5681 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5682 | return(standalone); |
| 5683 | } |
| 5684 | NEXT; |
| 5685 | SKIP_BLANKS; |
| 5686 | if (CUR == '\''){ |
| 5687 | NEXT; |
| 5688 | if ((CUR == 'n') && (NXT(1) == 'o')) { |
| 5689 | standalone = 0; |
| 5690 | SKIP(2); |
| 5691 | } else if ((CUR == 'y') && (NXT(1) == 'e') && |
| 5692 | (NXT(2) == 's')) { |
| 5693 | standalone = 1; |
| 5694 | SKIP(3); |
| 5695 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5696 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5697 | ctxt->sax->error(ctxt->userData, |
| 5698 | "standalone accepts only 'yes' or 'no'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5699 | ctxt->errNo = XML_ERR_STANDALONE_VALUE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5700 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5701 | } |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5702 | if (CUR != '\'') { |
| 5703 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5704 | ctxt->sax->error(ctxt->userData, "String not closed\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5705 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5706 | ctxt->wellFormed = 0; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5707 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5708 | NEXT; |
| 5709 | } else if (CUR == '"'){ |
| 5710 | NEXT; |
| 5711 | if ((CUR == 'n') && (NXT(1) == 'o')) { |
| 5712 | standalone = 0; |
| 5713 | SKIP(2); |
| 5714 | } else if ((CUR == 'y') && (NXT(1) == 'e') && |
| 5715 | (NXT(2) == 's')) { |
| 5716 | standalone = 1; |
| 5717 | SKIP(3); |
| 5718 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5719 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5720 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5721 | "standalone accepts only 'yes' or 'no'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5722 | ctxt->errNo = XML_ERR_STANDALONE_VALUE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5723 | ctxt->wellFormed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5724 | } |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5725 | if (CUR != '"') { |
| 5726 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5727 | ctxt->sax->error(ctxt->userData, "String not closed\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5728 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5729 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5730 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5731 | NEXT; |
| 5732 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5733 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5734 | ctxt->sax->error(ctxt->userData, |
| 5735 | "Standalone value not found\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5736 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5737 | ctxt->errNo = XML_ERR_STRING_NOT_STARTED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5738 | } |
| 5739 | } |
| 5740 | return(standalone); |
| 5741 | } |
| 5742 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5743 | /** |
| 5744 | * xmlParseXMLDecl: |
| 5745 | * @ctxt: an XML parser context |
| 5746 | * |
| 5747 | * parse an XML declaration header |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5748 | * |
| 5749 | * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' |
| 5750 | */ |
| 5751 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5752 | void |
| 5753 | xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5754 | xmlChar *version; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5755 | |
| 5756 | /* |
| 5757 | * We know that '<?xml' is here. |
| 5758 | */ |
| 5759 | SKIP(5); |
| 5760 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5761 | if (!IS_BLANK(CUR)) { |
| 5762 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5763 | ctxt->sax->error(ctxt->userData, "Blank needed after '<?xml'\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5764 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5765 | ctxt->wellFormed = 0; |
| 5766 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5767 | SKIP_BLANKS; |
| 5768 | |
| 5769 | /* |
| 5770 | * We should have the VersionInfo here. |
| 5771 | */ |
| 5772 | version = xmlParseVersionInfo(ctxt); |
| 5773 | if (version == NULL) |
| 5774 | version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5775 | ctxt->version = xmlStrdup(version); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5776 | xmlFree(version); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5777 | |
| 5778 | /* |
| 5779 | * We may have the encoding declaration |
| 5780 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5781 | if (!IS_BLANK(CUR)) { |
| 5782 | if ((CUR == '?') && (NXT(1) == '>')) { |
| 5783 | SKIP(2); |
| 5784 | return; |
| 5785 | } |
| 5786 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5787 | ctxt->sax->error(ctxt->userData, "Blank needed here\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5788 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5789 | ctxt->wellFormed = 0; |
| 5790 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5791 | ctxt->encoding = xmlParseEncodingDecl(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5792 | |
| 5793 | /* |
| 5794 | * We may have the standalone status. |
| 5795 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5796 | if ((ctxt->encoding != NULL) && (!IS_BLANK(CUR))) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5797 | if ((CUR == '?') && (NXT(1) == '>')) { |
| 5798 | SKIP(2); |
| 5799 | return; |
| 5800 | } |
| 5801 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5802 | ctxt->sax->error(ctxt->userData, "Blank needed here\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5803 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5804 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5805 | } |
| 5806 | SKIP_BLANKS; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5807 | ctxt->standalone = xmlParseSDDecl(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5808 | |
| 5809 | SKIP_BLANKS; |
| 5810 | if ((CUR == '?') && (NXT(1) == '>')) { |
| 5811 | SKIP(2); |
| 5812 | } else if (CUR == '>') { |
| 5813 | /* Deprecated old WD ... */ |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5814 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5815 | ctxt->sax->error(ctxt->userData, |
| 5816 | "XML declaration must end-up with '?>'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5817 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5818 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5819 | NEXT; |
| 5820 | } else { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5821 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5822 | ctxt->sax->error(ctxt->userData, |
| 5823 | "parsing XML declaration: '?>' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5824 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5825 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5826 | MOVETO_ENDTAG(CUR_PTR); |
| 5827 | NEXT; |
| 5828 | } |
| 5829 | } |
| 5830 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5831 | /** |
| 5832 | * xmlParseMisc: |
| 5833 | * @ctxt: an XML parser context |
| 5834 | * |
| 5835 | * parse an XML Misc* optionnal field. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5836 | * |
| 5837 | * [27] Misc ::= Comment | PI | S |
| 5838 | */ |
| 5839 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5840 | void |
| 5841 | xmlParseMisc(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5842 | while (((CUR == '<') && (NXT(1) == '?')) || |
| 5843 | ((CUR == '<') && (NXT(1) == '!') && |
| 5844 | (NXT(2) == '-') && (NXT(3) == '-')) || |
| 5845 | IS_BLANK(CUR)) { |
| 5846 | if ((CUR == '<') && (NXT(1) == '?')) { |
| 5847 | xmlParsePI(ctxt); |
| 5848 | } else if (IS_BLANK(CUR)) { |
| 5849 | NEXT; |
| 5850 | } else |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5851 | xmlParseComment(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5852 | } |
| 5853 | } |
| 5854 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5855 | /** |
| 5856 | * xmlParseDocument : |
| 5857 | * @ctxt: an XML parser context |
| 5858 | * |
| 5859 | * parse an XML document (and build a tree if using the standard SAX |
| 5860 | * interface). |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5861 | * |
| 5862 | * [1] document ::= prolog element Misc* |
| 5863 | * |
| 5864 | * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5865 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5866 | * Returns 0, -1 in case of error. the parser context is augmented |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5867 | * as a result of the parsing. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5868 | */ |
| 5869 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5870 | int |
| 5871 | xmlParseDocument(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5872 | xmlDefaultSAXHandlerInit(); |
| 5873 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5874 | GROW; |
| 5875 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5876 | /* |
| 5877 | * SAX: beginning of the document processing. |
| 5878 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5879 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5880 | ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5881 | |
| 5882 | /* |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5883 | * TODO We should check for encoding here and plug-in some |
| 5884 | * conversion code !!!! |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5885 | */ |
| 5886 | |
| 5887 | /* |
| 5888 | * Wipe out everything which is before the first '<' |
| 5889 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5890 | if (IS_BLANK(CUR)) { |
| 5891 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5892 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5893 | "Extra spaces at the beginning of the document are not allowed\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5894 | ctxt->errNo = XML_ERR_DOCUMENT_START; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5895 | ctxt->wellFormed = 0; |
| 5896 | SKIP_BLANKS; |
| 5897 | } |
| 5898 | |
| 5899 | if (CUR == 0) { |
| 5900 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5901 | ctxt->sax->error(ctxt->userData, "Document is empty\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5902 | ctxt->errNo = XML_ERR_DOCUMENT_EMPTY; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5903 | ctxt->wellFormed = 0; |
| 5904 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5905 | |
| 5906 | /* |
| 5907 | * Check for the XMLDecl in the Prolog. |
| 5908 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5909 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5910 | if ((CUR == '<') && (NXT(1) == '?') && |
| 5911 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 5912 | (NXT(4) == 'l')) { |
| 5913 | xmlParseXMLDecl(ctxt); |
| 5914 | /* SKIP_EOL(cur); */ |
| 5915 | SKIP_BLANKS; |
| 5916 | } else if ((CUR == '<') && (NXT(1) == '?') && |
| 5917 | (NXT(2) == 'X') && (NXT(3) == 'M') && |
| 5918 | (NXT(4) == 'L')) { |
| 5919 | /* |
| 5920 | * The first drafts were using <?XML and the final W3C REC |
| 5921 | * now use <?xml ... |
| 5922 | */ |
| 5923 | xmlParseXMLDecl(ctxt); |
| 5924 | /* SKIP_EOL(cur); */ |
| 5925 | SKIP_BLANKS; |
| 5926 | } else { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5927 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5928 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5929 | if ((ctxt->sax) && (ctxt->sax->startDocument)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5930 | ctxt->sax->startDocument(ctxt->userData); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5931 | |
| 5932 | /* |
| 5933 | * The Misc part of the Prolog |
| 5934 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5935 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5936 | xmlParseMisc(ctxt); |
| 5937 | |
| 5938 | /* |
| 5939 | * Then possibly doc type declaration(s) and more Misc |
| 5940 | * (doctypedecl Misc*)? |
| 5941 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5942 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5943 | if ((CUR == '<') && (NXT(1) == '!') && |
| 5944 | (NXT(2) == 'D') && (NXT(3) == 'O') && |
| 5945 | (NXT(4) == 'C') && (NXT(5) == 'T') && |
| 5946 | (NXT(6) == 'Y') && (NXT(7) == 'P') && |
| 5947 | (NXT(8) == 'E')) { |
| 5948 | xmlParseDocTypeDecl(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5949 | ctxt->instate = XML_PARSER_PROLOG; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5950 | xmlParseMisc(ctxt); |
| 5951 | } |
| 5952 | |
| 5953 | /* |
| 5954 | * Time to start parsing the tree itself |
| 5955 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5956 | GROW; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5957 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5958 | xmlParseElement(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5959 | ctxt->instate = XML_PARSER_EPILOG; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5960 | |
| 5961 | /* |
| 5962 | * The Misc part at the end |
| 5963 | */ |
| 5964 | xmlParseMisc(ctxt); |
| 5965 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5966 | if (CUR != 0) { |
| 5967 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5968 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5969 | "Extra content at the end of the document\n"); |
| 5970 | ctxt->wellFormed = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5971 | ctxt->errNo = XML_ERR_DOCUMENT_END; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5972 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5973 | ctxt->instate = XML_PARSER_EOF; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5974 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5975 | /* |
| 5976 | * SAX: end of the document processing. |
| 5977 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5978 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5979 | ctxt->sax->endDocument(ctxt->userData); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5980 | if (! ctxt->wellFormed) return(-1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5981 | return(0); |
| 5982 | } |
| 5983 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5984 | /************************************************************************ |
| 5985 | * * |
| 5986 | * I/O front end functions to the parser * |
| 5987 | * * |
| 5988 | ************************************************************************/ |
| 5989 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5990 | /** |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 5991 | * xmlCreateDocParserCtxt : |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5992 | * @cur: a pointer to an array of xmlChar |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 5993 | * |
| 5994 | * Create a parser context for an XML in-memory document. |
| 5995 | * |
| 5996 | * Returns the new parser context or NULL |
| 5997 | */ |
| 5998 | xmlParserCtxtPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5999 | xmlCreateDocParserCtxt(xmlChar *cur) { |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6000 | xmlParserCtxtPtr ctxt; |
| 6001 | xmlParserInputPtr input; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6002 | xmlCharEncoding enc; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6003 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6004 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6005 | if (ctxt == NULL) { |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6006 | return(NULL); |
| 6007 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6008 | input = xmlNewInputStream(ctxt); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6009 | if (input == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6010 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6011 | return(NULL); |
| 6012 | } |
| 6013 | |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6014 | /* |
| 6015 | * plug some encoding conversion routines here. !!! |
| 6016 | */ |
| 6017 | enc = xmlDetectCharEncoding(cur); |
| 6018 | xmlSwitchEncoding(ctxt, enc); |
| 6019 | |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6020 | input->base = cur; |
| 6021 | input->cur = cur; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6022 | |
| 6023 | inputPush(ctxt, input); |
| 6024 | return(ctxt); |
| 6025 | } |
| 6026 | |
| 6027 | /** |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6028 | * xmlSAXParseDoc : |
| 6029 | * @sax: the SAX handler block |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6030 | * @cur: a pointer to an array of xmlChar |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6031 | * @recovery: work in recovery mode, i.e. tries to read no Well Formed |
| 6032 | * documents |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6033 | * |
| 6034 | * parse an XML in-memory document and build a tree. |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6035 | * It use the given SAX function block to handle the parsing callback. |
| 6036 | * If sax is NULL, fallback to the default DOM tree building routines. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6037 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6038 | * Returns the resulting document tree |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6039 | */ |
| 6040 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6041 | xmlDocPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6042 | xmlSAXParseDoc(xmlSAXHandlerPtr sax, xmlChar *cur, int recovery) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6043 | xmlDocPtr ret; |
| 6044 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6045 | |
| 6046 | if (cur == NULL) return(NULL); |
| 6047 | |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6048 | |
| 6049 | ctxt = xmlCreateDocParserCtxt(cur); |
| 6050 | if (ctxt == NULL) return(NULL); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6051 | if (sax != NULL) { |
| 6052 | ctxt->sax = sax; |
| 6053 | ctxt->userData = NULL; |
| 6054 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6055 | |
| 6056 | xmlParseDocument(ctxt); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6057 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6058 | else { |
| 6059 | ret = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6060 | xmlFreeDoc(ctxt->myDoc); |
| 6061 | ctxt->myDoc = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6062 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 6063 | if (sax != NULL) |
| 6064 | ctxt->sax = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6065 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6066 | |
| 6067 | return(ret); |
| 6068 | } |
| 6069 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6070 | /** |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6071 | * xmlParseDoc : |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6072 | * @cur: a pointer to an array of xmlChar |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6073 | * |
| 6074 | * parse an XML in-memory document and build a tree. |
| 6075 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6076 | * Returns the resulting document tree |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6077 | */ |
| 6078 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6079 | xmlDocPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6080 | xmlParseDoc(xmlChar *cur) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6081 | return(xmlSAXParseDoc(NULL, cur, 0)); |
| 6082 | } |
| 6083 | |
| 6084 | /** |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6085 | * xmlSAXParseDTD : |
| 6086 | * @sax: the SAX handler block |
| 6087 | * @ExternalID: a NAME* containing the External ID of the DTD |
| 6088 | * @SystemID: a NAME* containing the URL to the DTD |
| 6089 | * |
| 6090 | * Load and parse an external subset. |
| 6091 | * |
| 6092 | * Returns the resulting xmlDtdPtr or NULL in case of error. |
| 6093 | */ |
| 6094 | |
| 6095 | xmlDtdPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6096 | xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, |
| 6097 | const xmlChar *SystemID) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6098 | xmlDtdPtr ret = NULL; |
| 6099 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6100 | xmlParserInputPtr input = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6101 | xmlCharEncoding enc; |
| 6102 | |
| 6103 | if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); |
| 6104 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6105 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6106 | if (ctxt == NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6107 | return(NULL); |
| 6108 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6109 | |
| 6110 | /* |
| 6111 | * Set-up the SAX context |
| 6112 | */ |
| 6113 | if (ctxt == NULL) return(NULL); |
| 6114 | if (sax != NULL) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6115 | if (ctxt->sax != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6116 | xmlFree(ctxt->sax); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6117 | ctxt->sax = sax; |
| 6118 | ctxt->userData = NULL; |
| 6119 | } |
| 6120 | |
| 6121 | /* |
| 6122 | * Ask the Entity resolver to load the damn thing |
| 6123 | */ |
| 6124 | |
| 6125 | if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) |
| 6126 | input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, SystemID); |
| 6127 | if (input == NULL) { |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 6128 | if (sax != NULL) ctxt->sax = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6129 | xmlFreeParserCtxt(ctxt); |
| 6130 | return(NULL); |
| 6131 | } |
| 6132 | |
| 6133 | /* |
| 6134 | * plug some encoding conversion routines here. !!! |
| 6135 | */ |
| 6136 | xmlPushInput(ctxt, input); |
| 6137 | enc = xmlDetectCharEncoding(ctxt->input->cur); |
| 6138 | xmlSwitchEncoding(ctxt, enc); |
| 6139 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6140 | if (input->filename == NULL) |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6141 | input->filename = (char *) xmlStrdup(SystemID); /* !!!!!!! */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6142 | input->line = 1; |
| 6143 | input->col = 1; |
| 6144 | input->base = ctxt->input->cur; |
| 6145 | input->cur = ctxt->input->cur; |
| 6146 | input->free = NULL; |
| 6147 | |
| 6148 | /* |
| 6149 | * let's parse that entity knowing it's an external subset. |
| 6150 | */ |
| 6151 | xmlParseExternalSubset(ctxt, ExternalID, SystemID); |
| 6152 | |
| 6153 | if (ctxt->myDoc != NULL) { |
| 6154 | if (ctxt->wellFormed) { |
| 6155 | ret = ctxt->myDoc->intSubset; |
| 6156 | ctxt->myDoc->intSubset = NULL; |
| 6157 | } else { |
| 6158 | ret = NULL; |
| 6159 | } |
| 6160 | xmlFreeDoc(ctxt->myDoc); |
| 6161 | ctxt->myDoc = NULL; |
| 6162 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 6163 | if (sax != NULL) ctxt->sax = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6164 | xmlFreeParserCtxt(ctxt); |
| 6165 | |
| 6166 | return(ret); |
| 6167 | } |
| 6168 | |
| 6169 | /** |
| 6170 | * xmlParseDTD : |
| 6171 | * @ExternalID: a NAME* containing the External ID of the DTD |
| 6172 | * @SystemID: a NAME* containing the URL to the DTD |
| 6173 | * |
| 6174 | * Load and parse an external subset. |
| 6175 | * |
| 6176 | * Returns the resulting xmlDtdPtr or NULL in case of error. |
| 6177 | */ |
| 6178 | |
| 6179 | xmlDtdPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6180 | xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6181 | return(xmlSAXParseDTD(NULL, ExternalID, SystemID)); |
| 6182 | } |
| 6183 | |
| 6184 | /** |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6185 | * xmlRecoverDoc : |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6186 | * @cur: a pointer to an array of xmlChar |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6187 | * |
| 6188 | * parse an XML in-memory document and build a tree. |
| 6189 | * In the case the document is not Well Formed, a tree is built anyway |
| 6190 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6191 | * Returns the resulting document tree |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6192 | */ |
| 6193 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6194 | xmlDocPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6195 | xmlRecoverDoc(xmlChar *cur) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6196 | return(xmlSAXParseDoc(NULL, cur, 1)); |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6200 | * xmlCreateFileParserCtxt : |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6201 | * @filename: the filename |
| 6202 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6203 | * Create a parser context for a file content. |
| 6204 | * Automatic support for ZLIB/Compress compressed document is provided |
| 6205 | * by default if found at compile-time. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6206 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6207 | * Returns the new parser context or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6208 | */ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6209 | xmlParserCtxtPtr |
| 6210 | xmlCreateFileParserCtxt(const char *filename) |
| 6211 | { |
| 6212 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6213 | xmlParserInputPtr inputStream; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6214 | xmlParserInputBufferPtr buf; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6215 | char *directory = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6216 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6217 | buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
| 6218 | if (buf == NULL) return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6219 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6220 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6221 | if (ctxt == NULL) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6222 | return(NULL); |
| 6223 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6224 | |
| 6225 | inputStream = xmlNewInputStream(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6226 | if (inputStream == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6227 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6228 | return(NULL); |
| 6229 | } |
| 6230 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6231 | inputStream->filename = xmlMemStrdup(filename); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6232 | inputStream->buf = buf; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6233 | inputStream->base = inputStream->buf->buffer->content; |
| 6234 | inputStream->cur = inputStream->buf->buffer->content; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6235 | |
| 6236 | inputPush(ctxt, inputStream); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6237 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 6238 | directory = xmlParserGetDirectory(filename); |
| 6239 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 6240 | ctxt->directory = directory; |
| 6241 | |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6242 | return(ctxt); |
| 6243 | } |
| 6244 | |
| 6245 | /** |
| 6246 | * xmlSAXParseFile : |
| 6247 | * @sax: the SAX handler block |
| 6248 | * @filename: the filename |
| 6249 | * @recovery: work in recovery mode, i.e. tries to read no Well Formed |
| 6250 | * documents |
| 6251 | * |
| 6252 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress |
| 6253 | * compressed document is provided by default if found at compile-time. |
| 6254 | * It use the given SAX function block to handle the parsing callback. |
| 6255 | * If sax is NULL, fallback to the default DOM tree building routines. |
| 6256 | * |
| 6257 | * Returns the resulting document tree |
| 6258 | */ |
| 6259 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6260 | xmlDocPtr |
| 6261 | xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename, |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6262 | int recovery) { |
| 6263 | xmlDocPtr ret; |
| 6264 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6265 | char *directory = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6266 | |
| 6267 | ctxt = xmlCreateFileParserCtxt(filename); |
| 6268 | if (ctxt == NULL) return(NULL); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6269 | if (sax != NULL) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6270 | if (ctxt->sax != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6271 | xmlFree(ctxt->sax); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6272 | ctxt->sax = sax; |
| 6273 | ctxt->userData = NULL; |
| 6274 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6275 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6276 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 6277 | directory = xmlParserGetDirectory(filename); |
| 6278 | if ((ctxt->directory == NULL) && (directory != NULL)) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6279 | ctxt->directory = (char *) xmlStrdup((xmlChar *) directory); /* !!!!!!! */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6280 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6281 | xmlParseDocument(ctxt); |
| 6282 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6283 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6284 | else { |
| 6285 | ret = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6286 | xmlFreeDoc(ctxt->myDoc); |
| 6287 | ctxt->myDoc = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6288 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 6289 | if (sax != NULL) |
| 6290 | ctxt->sax = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6291 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6292 | |
| 6293 | return(ret); |
| 6294 | } |
| 6295 | |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6296 | /** |
| 6297 | * xmlParseFile : |
| 6298 | * @filename: the filename |
| 6299 | * |
| 6300 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress |
| 6301 | * compressed document is provided by default if found at compile-time. |
| 6302 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6303 | * Returns the resulting document tree |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6304 | */ |
| 6305 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6306 | xmlDocPtr |
| 6307 | xmlParseFile(const char *filename) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6308 | return(xmlSAXParseFile(NULL, filename, 0)); |
| 6309 | } |
| 6310 | |
| 6311 | /** |
| 6312 | * xmlRecoverFile : |
| 6313 | * @filename: the filename |
| 6314 | * |
| 6315 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress |
| 6316 | * compressed document is provided by default if found at compile-time. |
| 6317 | * In the case the document is not Well Formed, a tree is built anyway |
| 6318 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6319 | * Returns the resulting document tree |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6320 | */ |
| 6321 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6322 | xmlDocPtr |
| 6323 | xmlRecoverFile(const char *filename) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6324 | return(xmlSAXParseFile(NULL, filename, 1)); |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6325 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6326 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6327 | /** |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6328 | * xmlCreateMemoryParserCtxt : |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6329 | * @buffer: an pointer to a char array |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6330 | * @size: the siwe of the array |
| 6331 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6332 | * Create a parser context for an XML in-memory document. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6333 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6334 | * Returns the new parser context or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6335 | */ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6336 | xmlParserCtxtPtr |
| 6337 | xmlCreateMemoryParserCtxt(char *buffer, int size) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6338 | xmlParserCtxtPtr ctxt; |
| 6339 | xmlParserInputPtr input; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6340 | xmlCharEncoding enc; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6341 | |
| 6342 | buffer[size - 1] = '\0'; |
| 6343 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6344 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6345 | if (ctxt == NULL) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6346 | return(NULL); |
| 6347 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6348 | |
| 6349 | input = xmlNewInputStream(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6350 | if (input == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6351 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6352 | return(NULL); |
| 6353 | } |
| 6354 | |
| 6355 | input->filename = NULL; |
| 6356 | input->line = 1; |
| 6357 | input->col = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6358 | input->buf = NULL; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6359 | input->consumed = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6360 | |
| 6361 | /* |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6362 | * plug some encoding conversion routines here. !!! |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6363 | */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6364 | enc = xmlDetectCharEncoding(BAD_CAST buffer); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6365 | xmlSwitchEncoding(ctxt, enc); |
| 6366 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6367 | input->base = BAD_CAST buffer; |
| 6368 | input->cur = BAD_CAST buffer; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6369 | input->free = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6370 | |
| 6371 | inputPush(ctxt, input); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6372 | return(ctxt); |
| 6373 | } |
| 6374 | |
| 6375 | /** |
| 6376 | * xmlSAXParseMemory : |
| 6377 | * @sax: the SAX handler block |
| 6378 | * @buffer: an pointer to a char array |
| 6379 | * @size: the siwe of the array |
| 6380 | * @recovery: work in recovery mode, i.e. tries to read no Well Formed |
| 6381 | * documents |
| 6382 | * |
| 6383 | * parse an XML in-memory block and use the given SAX function block |
| 6384 | * to handle the parsing callback. If sax is NULL, fallback to the default |
| 6385 | * DOM tree building routines. |
| 6386 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6387 | * Returns the resulting document tree |
| 6388 | */ |
| 6389 | xmlDocPtr |
| 6390 | xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer, int size, int recovery) { |
| 6391 | xmlDocPtr ret; |
| 6392 | xmlParserCtxtPtr ctxt; |
| 6393 | |
| 6394 | ctxt = xmlCreateMemoryParserCtxt(buffer, size); |
| 6395 | if (ctxt == NULL) return(NULL); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6396 | if (sax != NULL) { |
| 6397 | ctxt->sax = sax; |
| 6398 | ctxt->userData = NULL; |
| 6399 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6400 | |
| 6401 | xmlParseDocument(ctxt); |
| 6402 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6403 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6404 | else { |
| 6405 | ret = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6406 | xmlFreeDoc(ctxt->myDoc); |
| 6407 | ctxt->myDoc = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6408 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 6409 | if (sax != NULL) |
| 6410 | ctxt->sax = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 6411 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6412 | |
| 6413 | return(ret); |
| 6414 | } |
| 6415 | |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6416 | /** |
| 6417 | * xmlParseMemory : |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6418 | * @buffer: an pointer to a char array |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6419 | * @size: the size of the array |
| 6420 | * |
| 6421 | * parse an XML in-memory block and build a tree. |
| 6422 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6423 | * Returns the resulting document tree |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6424 | */ |
| 6425 | |
| 6426 | xmlDocPtr xmlParseMemory(char *buffer, int size) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6427 | return(xmlSAXParseMemory(NULL, buffer, size, 0)); |
| 6428 | } |
| 6429 | |
| 6430 | /** |
| 6431 | * xmlRecoverMemory : |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6432 | * @buffer: an pointer to a char array |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6433 | * @size: the size of the array |
| 6434 | * |
| 6435 | * parse an XML in-memory block and build a tree. |
| 6436 | * In the case the document is not Well Formed, a tree is built anyway |
| 6437 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6438 | * Returns the resulting document tree |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6439 | */ |
| 6440 | |
| 6441 | xmlDocPtr xmlRecoverMemory(char *buffer, int size) { |
| 6442 | return(xmlSAXParseMemory(NULL, buffer, size, 1)); |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 6443 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6444 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6445 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6446 | /** |
| 6447 | * xmlSetupParserForBuffer: |
| 6448 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6449 | * @buffer: a xmlChar * buffer |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6450 | * @filename: a file name |
| 6451 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6452 | * Setup the parser context to parse a new buffer; Clears any prior |
| 6453 | * contents from the parser context. The buffer parameter must not be |
| 6454 | * NULL, but the filename parameter can be |
| 6455 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6456 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6457 | xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6458 | const char* filename) |
| 6459 | { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6460 | xmlParserInputPtr input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6461 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6462 | input = xmlNewInputStream(ctxt); |
| 6463 | if (input == NULL) { |
| 6464 | perror("malloc"); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6465 | xmlFree(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6466 | exit(1); |
| 6467 | } |
| 6468 | |
| 6469 | xmlClearParserCtxt(ctxt); |
| 6470 | if (filename != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6471 | input->filename = xmlMemStrdup(filename); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6472 | input->base = buffer; |
| 6473 | input->cur = buffer; |
| 6474 | inputPush(ctxt, input); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6478 | /************************************************************************ |
| 6479 | * * |
| 6480 | * Miscelaneous * |
| 6481 | * * |
| 6482 | ************************************************************************/ |
| 6483 | |
| 6484 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6485 | /** |
| 6486 | * xmlParserFindNodeInfo: |
| 6487 | * @ctxt: an XML parser context |
| 6488 | * @node: an XML node within the tree |
| 6489 | * |
| 6490 | * Find the parser node info struct for a given node |
| 6491 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6492 | * Returns an xmlParserNodeInfo block pointer or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6493 | */ |
| 6494 | const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* ctx, |
| 6495 | const xmlNode* node) |
| 6496 | { |
| 6497 | unsigned long pos; |
| 6498 | |
| 6499 | /* Find position where node should be at */ |
| 6500 | pos = xmlParserFindNodeInfoIndex(&ctx->node_seq, node); |
| 6501 | if ( ctx->node_seq.buffer[pos].node == node ) |
| 6502 | return &ctx->node_seq.buffer[pos]; |
| 6503 | else |
| 6504 | return NULL; |
| 6505 | } |
| 6506 | |
| 6507 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6508 | /** |
| 6509 | * xmlInitNodeInfoSeq : |
| 6510 | * @seq: a node info sequence pointer |
| 6511 | * |
| 6512 | * -- Initialize (set to initial state) node info sequence |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6513 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6514 | void |
| 6515 | xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6516 | { |
| 6517 | seq->length = 0; |
| 6518 | seq->maximum = 0; |
| 6519 | seq->buffer = NULL; |
| 6520 | } |
| 6521 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6522 | /** |
| 6523 | * xmlClearNodeInfoSeq : |
| 6524 | * @seq: a node info sequence pointer |
| 6525 | * |
| 6526 | * -- Clear (release memory and reinitialize) node |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6527 | * info sequence |
| 6528 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6529 | void |
| 6530 | xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6531 | { |
| 6532 | if ( seq->buffer != NULL ) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6533 | xmlFree(seq->buffer); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6534 | xmlInitNodeInfoSeq(seq); |
| 6535 | } |
| 6536 | |
| 6537 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6538 | /** |
| 6539 | * xmlParserFindNodeInfoIndex: |
| 6540 | * @seq: a node info sequence pointer |
| 6541 | * @node: an XML node pointer |
| 6542 | * |
| 6543 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6544 | * xmlParserFindNodeInfoIndex : Find the index that the info record for |
| 6545 | * the given node is or should be at in a sorted sequence |
Daniel Veillard | 1164e75 | 1999-02-16 16:29:17 +0000 | [diff] [blame] | 6546 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6547 | * Returns a long indicating the position of the record |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6548 | */ |
| 6549 | unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq, |
| 6550 | const xmlNode* node) |
| 6551 | { |
| 6552 | unsigned long upper, lower, middle; |
| 6553 | int found = 0; |
| 6554 | |
| 6555 | /* Do a binary search for the key */ |
| 6556 | lower = 1; |
| 6557 | upper = seq->length; |
| 6558 | middle = 0; |
| 6559 | while ( lower <= upper && !found) { |
| 6560 | middle = lower + (upper - lower) / 2; |
| 6561 | if ( node == seq->buffer[middle - 1].node ) |
| 6562 | found = 1; |
| 6563 | else if ( node < seq->buffer[middle - 1].node ) |
| 6564 | upper = middle - 1; |
| 6565 | else |
| 6566 | lower = middle + 1; |
| 6567 | } |
| 6568 | |
| 6569 | /* Return position */ |
| 6570 | if ( middle == 0 || seq->buffer[middle - 1].node < node ) |
| 6571 | return middle; |
| 6572 | else |
| 6573 | return middle - 1; |
| 6574 | } |
| 6575 | |
| 6576 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6577 | /** |
| 6578 | * xmlParserAddNodeInfo: |
| 6579 | * @ctxt: an XML parser context |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6580 | * @info: a node info sequence pointer |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6581 | * |
| 6582 | * Insert node info record into the sorted sequence |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6583 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6584 | void |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6585 | xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6586 | const xmlParserNodeInfo* info) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6587 | { |
| 6588 | unsigned long pos; |
| 6589 | static unsigned int block_size = 5; |
| 6590 | |
| 6591 | /* Find pos and check to see if node is already in the sequence */ |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6592 | pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, info->node); |
| 6593 | if ( pos < ctxt->node_seq.length |
| 6594 | && ctxt->node_seq.buffer[pos].node == info->node ) { |
| 6595 | ctxt->node_seq.buffer[pos] = *info; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | /* Otherwise, we need to add new node to buffer */ |
| 6599 | else { |
| 6600 | /* Expand buffer by 5 if needed */ |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6601 | if ( ctxt->node_seq.length + 1 > ctxt->node_seq.maximum ) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6602 | xmlParserNodeInfo* tmp_buffer; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6603 | unsigned int byte_size = (sizeof(*ctxt->node_seq.buffer) |
| 6604 | *(ctxt->node_seq.maximum + block_size)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6605 | |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6606 | if ( ctxt->node_seq.buffer == NULL ) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6607 | tmp_buffer = (xmlParserNodeInfo*) xmlMalloc(byte_size); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6608 | else |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6609 | tmp_buffer = (xmlParserNodeInfo*) xmlRealloc(ctxt->node_seq.buffer, byte_size); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6610 | |
| 6611 | if ( tmp_buffer == NULL ) { |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6612 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6613 | ctxt->sax->error(ctxt->userData, "Out of memory\n"); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6614 | ctxt->errNo = XML_ERR_NO_MEMORY; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6615 | return; |
| 6616 | } |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6617 | ctxt->node_seq.buffer = tmp_buffer; |
| 6618 | ctxt->node_seq.maximum += block_size; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | /* If position is not at end, move elements out of the way */ |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6622 | if ( pos != ctxt->node_seq.length ) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6623 | unsigned long i; |
| 6624 | |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6625 | for ( i = ctxt->node_seq.length; i > pos; i-- ) |
| 6626 | ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1]; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6627 | } |
| 6628 | |
| 6629 | /* Copy element and increase length */ |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6630 | ctxt->node_seq.buffer[pos] = *info; |
| 6631 | ctxt->node_seq.length++; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6632 | } |
| 6633 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6634 | |
| 6635 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6636 | /** |
| 6637 | * xmlSubstituteEntitiesDefault : |
| 6638 | * @val: int 0 or 1 |
| 6639 | * |
| 6640 | * Set and return the previous value for default entity support. |
| 6641 | * Initially the parser always keep entity references instead of substituting |
| 6642 | * entity values in the output. This function has to be used to change the |
| 6643 | * default parser behaviour |
| 6644 | * SAX::subtituteEntities() has to be used for changing that on a file by |
| 6645 | * file basis. |
| 6646 | * |
| 6647 | * Returns the last value for 0 for no substitution, 1 for substitution. |
| 6648 | */ |
| 6649 | |
| 6650 | int |
| 6651 | xmlSubstituteEntitiesDefault(int val) { |
| 6652 | int old = xmlSubstituteEntitiesDefaultValue; |
| 6653 | |
| 6654 | xmlSubstituteEntitiesDefaultValue = val; |
| 6655 | return(old); |
| 6656 | } |
| 6657 | |