Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SAX2.c : Default SAX2 handler to build a tree. |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
| 6 | * Daniel Veillard <daniel@veillard.com> |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #define IN_LIBXML |
| 11 | #include "libxml.h" |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
Daniel Veillard | 1dc9feb | 2008-11-17 15:59:21 +0000 | [diff] [blame] | 14 | #include <limits.h> |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 15 | #include <libxml/xmlmemory.h> |
| 16 | #include <libxml/tree.h> |
| 17 | #include <libxml/parser.h> |
| 18 | #include <libxml/parserInternals.h> |
| 19 | #include <libxml/valid.h> |
| 20 | #include <libxml/entities.h> |
| 21 | #include <libxml/xmlerror.h> |
| 22 | #include <libxml/debugXML.h> |
| 23 | #include <libxml/xmlIO.h> |
| 24 | #include <libxml/SAX.h> |
| 25 | #include <libxml/uri.h> |
| 26 | #include <libxml/valid.h> |
| 27 | #include <libxml/HTMLtree.h> |
| 28 | #include <libxml/globals.h> |
| 29 | |
Daniel Veillard | 1dc9feb | 2008-11-17 15:59:21 +0000 | [diff] [blame] | 30 | /* Define SIZE_T_MAX unless defined through <limits.h>. */ |
| 31 | #ifndef SIZE_T_MAX |
| 32 | # define SIZE_T_MAX ((size_t)-1) |
| 33 | #endif /* !SIZE_T_MAX */ |
| 34 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 35 | /* #define DEBUG_SAX2 */ |
| 36 | /* #define DEBUG_SAX2_TREE */ |
| 37 | |
| 38 | /** |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 39 | * TODO: |
| 40 | * |
| 41 | * macro to flag unimplemented blocks |
| 42 | * XML_CATALOG_PREFER user env to select between system/public prefered |
| 43 | * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk> |
| 44 | *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with |
| 45 | *> values "system" and "public". I have made the default be "system" to |
| 46 | *> match yours. |
| 47 | */ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 48 | #define TODO \ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 49 | xmlGenericError(xmlGenericErrorContext, \ |
| 50 | "Unimplemented block at %s:%d\n", \ |
| 51 | __FILE__, __LINE__); |
| 52 | |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 53 | /* |
| 54 | * xmlSAX2ErrMemory: |
| 55 | * @ctxt: an XML validation parser context |
| 56 | * @msg: a string to accompany the error message |
| 57 | */ |
| 58 | static void |
William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 59 | xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt, const char *msg) { |
Daniel Veillard | 740cb1a | 2012-07-18 16:05:37 +0800 | [diff] [blame] | 60 | xmlStructuredErrorFunc schannel = NULL; |
| 61 | const char *str1 = "out of memory\n"; |
| 62 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 63 | if (ctxt != NULL) { |
Daniel Veillard | 740cb1a | 2012-07-18 16:05:37 +0800 | [diff] [blame] | 64 | ctxt->errNo = XML_ERR_NO_MEMORY; |
| 65 | if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) |
| 66 | schannel = ctxt->sax->serror; |
| 67 | __xmlRaiseError(schannel, |
| 68 | ctxt->vctxt.error, ctxt->vctxt.userData, |
| 69 | ctxt, NULL, XML_FROM_PARSER, XML_ERR_NO_MEMORY, |
| 70 | XML_ERR_ERROR, NULL, 0, (const char *) str1, |
| 71 | NULL, NULL, 0, 0, |
| 72 | msg, (const char *) str1, NULL); |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 73 | ctxt->errNo = XML_ERR_NO_MEMORY; |
| 74 | ctxt->instate = XML_PARSER_EOF; |
| 75 | ctxt->disableSAX = 1; |
Daniel Veillard | 740cb1a | 2012-07-18 16:05:37 +0800 | [diff] [blame] | 76 | } else { |
| 77 | __xmlRaiseError(schannel, |
| 78 | NULL, NULL, |
| 79 | ctxt, NULL, XML_FROM_PARSER, XML_ERR_NO_MEMORY, |
| 80 | XML_ERR_ERROR, NULL, 0, (const char *) str1, |
| 81 | NULL, NULL, 0, 0, |
| 82 | msg, (const char *) str1, NULL); |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 83 | } |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 86 | /** |
Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 87 | * xmlValidError: |
| 88 | * @ctxt: an XML validation parser context |
| 89 | * @error: the error number |
| 90 | * @msg: the error message |
| 91 | * @str1: extra data |
| 92 | * @str2: extra data |
| 93 | * |
| 94 | * Handle a validation error |
| 95 | */ |
| 96 | static void |
| 97 | xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error, |
| 98 | const char *msg, const char *str1, const char *str2) |
| 99 | { |
| 100 | xmlStructuredErrorFunc schannel = NULL; |
| 101 | |
| 102 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && |
| 103 | (ctxt->instate == XML_PARSER_EOF)) |
| 104 | return; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 105 | if (ctxt != NULL) { |
| 106 | ctxt->errNo = error; |
| 107 | if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) |
| 108 | schannel = ctxt->sax->serror; |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 109 | __xmlRaiseError(schannel, |
| 110 | ctxt->vctxt.error, ctxt->vctxt.userData, |
| 111 | ctxt, NULL, XML_FROM_DTD, error, |
| 112 | XML_ERR_ERROR, NULL, 0, (const char *) str1, |
| 113 | (const char *) str2, NULL, 0, 0, |
| 114 | msg, (const char *) str1, (const char *) str2); |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 115 | ctxt->valid = 0; |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 116 | } else { |
| 117 | __xmlRaiseError(schannel, |
| 118 | NULL, NULL, |
| 119 | ctxt, NULL, XML_FROM_DTD, error, |
| 120 | XML_ERR_ERROR, NULL, 0, (const char *) str1, |
| 121 | (const char *) str2, NULL, 0, 0, |
| 122 | msg, (const char *) str1, (const char *) str2); |
| 123 | } |
Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 127 | * xmlFatalErrMsg: |
| 128 | * @ctxt: an XML parser context |
| 129 | * @error: the error number |
| 130 | * @msg: the error message |
| 131 | * @str1: an error string |
| 132 | * @str2: an error string |
| 133 | * |
| 134 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints |
| 135 | */ |
| 136 | static void |
| 137 | xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, |
| 138 | const char *msg, const xmlChar *str1, const xmlChar *str2) |
| 139 | { |
| 140 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && |
| 141 | (ctxt->instate == XML_PARSER_EOF)) |
| 142 | return; |
| 143 | if (ctxt != NULL) |
| 144 | ctxt->errNo = error; |
| 145 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 146 | XML_ERR_FATAL, NULL, 0, |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 147 | (const char *) str1, (const char *) str2, |
| 148 | NULL, 0, 0, msg, str1, str2); |
| 149 | if (ctxt != NULL) { |
| 150 | ctxt->wellFormed = 0; |
| 151 | ctxt->valid = 0; |
| 152 | if (ctxt->recovery == 0) |
| 153 | ctxt->disableSAX = 1; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * xmlWarnMsg: |
| 159 | * @ctxt: an XML parser context |
| 160 | * @error: the error number |
| 161 | * @msg: the error message |
| 162 | * @str1: an error string |
| 163 | * @str2: an error string |
| 164 | * |
| 165 | * Handle a parser warning |
| 166 | */ |
| 167 | static void |
| 168 | xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, |
| 169 | const char *msg, const xmlChar *str1) |
| 170 | { |
| 171 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && |
| 172 | (ctxt->instate == XML_PARSER_EOF)) |
| 173 | return; |
| 174 | if (ctxt != NULL) |
| 175 | ctxt->errNo = error; |
| 176 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 177 | XML_ERR_WARNING, NULL, 0, |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 178 | (const char *) str1, NULL, |
| 179 | NULL, 0, 0, msg, str1); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * xmlNsErrMsg: |
| 184 | * @ctxt: an XML parser context |
| 185 | * @error: the error number |
| 186 | * @msg: the error message |
| 187 | * @str1: an error string |
| 188 | * @str2: an error string |
| 189 | * |
| 190 | * Handle a namespace error |
| 191 | */ |
| 192 | static void |
| 193 | xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, |
| 194 | const char *msg, const xmlChar *str1, const xmlChar *str2) |
| 195 | { |
| 196 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && |
| 197 | (ctxt->instate == XML_PARSER_EOF)) |
| 198 | return; |
| 199 | if (ctxt != NULL) |
| 200 | ctxt->errNo = error; |
| 201 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 202 | XML_ERR_ERROR, NULL, 0, |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 203 | (const char *) str1, (const char *) str2, |
| 204 | NULL, 0, 0, msg, str1, str2); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * xmlNsWarnMsg: |
| 209 | * @ctxt: an XML parser context |
| 210 | * @error: the error number |
| 211 | * @msg: the error message |
| 212 | * @str1: an error string |
| 213 | * |
| 214 | * Handle a namespace warning |
| 215 | */ |
| 216 | static void |
| 217 | xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, |
| 218 | const char *msg, const xmlChar *str1, const xmlChar *str2) |
| 219 | { |
| 220 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && |
| 221 | (ctxt->instate == XML_PARSER_EOF)) |
| 222 | return; |
| 223 | if (ctxt != NULL) |
| 224 | ctxt->errNo = error; |
| 225 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 226 | XML_ERR_WARNING, NULL, 0, |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 227 | (const char *) str1, (const char *) str2, |
| 228 | NULL, 0, 0, msg, str1, str2); |
| 229 | } |
| 230 | |
| 231 | /** |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 232 | * xmlSAX2GetPublicId: |
| 233 | * @ctx: the user data (XML parser context) |
| 234 | * |
| 235 | * Provides the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN" |
| 236 | * |
| 237 | * Returns a xmlChar * |
| 238 | */ |
| 239 | const xmlChar * |
| 240 | xmlSAX2GetPublicId(void *ctx ATTRIBUTE_UNUSED) |
| 241 | { |
| 242 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
| 243 | return(NULL); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * xmlSAX2GetSystemId: |
| 248 | * @ctx: the user data (XML parser context) |
| 249 | * |
| 250 | * Provides the system ID, basically URL or filename e.g. |
| 251 | * http://www.sgmlsource.com/dtds/memo.dtd |
| 252 | * |
| 253 | * Returns a xmlChar * |
| 254 | */ |
| 255 | const xmlChar * |
| 256 | xmlSAX2GetSystemId(void *ctx) |
| 257 | { |
| 258 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 259 | if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 260 | return((const xmlChar *) ctxt->input->filename); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
| 264 | * xmlSAX2GetLineNumber: |
| 265 | * @ctx: the user data (XML parser context) |
| 266 | * |
| 267 | * Provide the line number of the current parsing point. |
| 268 | * |
| 269 | * Returns an int |
| 270 | */ |
| 271 | int |
| 272 | xmlSAX2GetLineNumber(void *ctx) |
| 273 | { |
| 274 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 275 | if ((ctx == NULL) || (ctxt->input == NULL)) return(0); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 276 | return(ctxt->input->line); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * xmlSAX2GetColumnNumber: |
| 281 | * @ctx: the user data (XML parser context) |
| 282 | * |
| 283 | * Provide the column number of the current parsing point. |
| 284 | * |
| 285 | * Returns an int |
| 286 | */ |
| 287 | int |
| 288 | xmlSAX2GetColumnNumber(void *ctx) |
| 289 | { |
| 290 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 291 | if ((ctx == NULL) || (ctxt->input == NULL)) return(0); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 292 | return(ctxt->input->col); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * xmlSAX2IsStandalone: |
| 297 | * @ctx: the user data (XML parser context) |
| 298 | * |
| 299 | * Is this document tagged standalone ? |
| 300 | * |
| 301 | * Returns 1 if true |
| 302 | */ |
| 303 | int |
| 304 | xmlSAX2IsStandalone(void *ctx) |
| 305 | { |
| 306 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 307 | if ((ctx == NULL) || (ctxt->myDoc == NULL)) return(0); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 308 | return(ctxt->myDoc->standalone == 1); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * xmlSAX2HasInternalSubset: |
| 313 | * @ctx: the user data (XML parser context) |
| 314 | * |
| 315 | * Does this document has an internal subset |
| 316 | * |
| 317 | * Returns 1 if true |
| 318 | */ |
| 319 | int |
| 320 | xmlSAX2HasInternalSubset(void *ctx) |
| 321 | { |
| 322 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 323 | if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 324 | return(ctxt->myDoc->intSubset != NULL); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * xmlSAX2HasExternalSubset: |
| 329 | * @ctx: the user data (XML parser context) |
| 330 | * |
| 331 | * Does this document has an external subset |
| 332 | * |
| 333 | * Returns 1 if true |
| 334 | */ |
| 335 | int |
| 336 | xmlSAX2HasExternalSubset(void *ctx) |
| 337 | { |
| 338 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 339 | if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 340 | return(ctxt->myDoc->extSubset != NULL); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * xmlSAX2InternalSubset: |
| 345 | * @ctx: the user data (XML parser context) |
| 346 | * @name: the root element name |
| 347 | * @ExternalID: the external ID |
| 348 | * @SystemID: the SYSTEM ID (e.g. filename or URL) |
| 349 | * |
| 350 | * Callback on internal subset declaration. |
| 351 | */ |
| 352 | void |
| 353 | xmlSAX2InternalSubset(void *ctx, const xmlChar *name, |
| 354 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 355 | { |
| 356 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 357 | xmlDtdPtr dtd; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 358 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 359 | #ifdef DEBUG_SAX |
| 360 | xmlGenericError(xmlGenericErrorContext, |
| 361 | "SAX.xmlSAX2InternalSubset(%s, %s, %s)\n", |
| 362 | name, ExternalID, SystemID); |
| 363 | #endif |
| 364 | |
| 365 | if (ctxt->myDoc == NULL) |
| 366 | return; |
| 367 | dtd = xmlGetIntSubset(ctxt->myDoc); |
| 368 | if (dtd != NULL) { |
| 369 | if (ctxt->html) |
| 370 | return; |
| 371 | xmlUnlinkNode((xmlNodePtr) dtd); |
| 372 | xmlFreeDtd(dtd); |
| 373 | ctxt->myDoc->intSubset = NULL; |
| 374 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 375 | ctxt->myDoc->intSubset = |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 376 | xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID); |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 377 | if (ctxt->myDoc->intSubset == NULL) |
| 378 | xmlSAX2ErrMemory(ctxt, "xmlSAX2InternalSubset"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** |
| 382 | * xmlSAX2ExternalSubset: |
| 383 | * @ctx: the user data (XML parser context) |
| 384 | * @name: the root element name |
| 385 | * @ExternalID: the external ID |
| 386 | * @SystemID: the SYSTEM ID (e.g. filename or URL) |
| 387 | * |
| 388 | * Callback on external subset declaration. |
| 389 | */ |
| 390 | void |
| 391 | xmlSAX2ExternalSubset(void *ctx, const xmlChar *name, |
| 392 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 393 | { |
| 394 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 395 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 396 | #ifdef DEBUG_SAX |
| 397 | xmlGenericError(xmlGenericErrorContext, |
| 398 | "SAX.xmlSAX2ExternalSubset(%s, %s, %s)\n", |
| 399 | name, ExternalID, SystemID); |
| 400 | #endif |
| 401 | if (((ExternalID != NULL) || (SystemID != NULL)) && |
| 402 | (((ctxt->validate) || (ctxt->loadsubset != 0)) && |
| 403 | (ctxt->wellFormed && ctxt->myDoc))) { |
| 404 | /* |
| 405 | * Try to fetch and parse the external subset. |
| 406 | */ |
| 407 | xmlParserInputPtr oldinput; |
| 408 | int oldinputNr; |
| 409 | int oldinputMax; |
| 410 | xmlParserInputPtr *oldinputTab; |
| 411 | xmlParserInputPtr input = NULL; |
| 412 | xmlCharEncoding enc; |
| 413 | int oldcharset; |
| 414 | |
| 415 | /* |
| 416 | * Ask the Entity resolver to load the damn thing |
| 417 | */ |
| 418 | if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) |
| 419 | input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, |
| 420 | SystemID); |
| 421 | if (input == NULL) { |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | xmlNewDtd(ctxt->myDoc, name, ExternalID, SystemID); |
| 426 | |
| 427 | /* |
| 428 | * make sure we won't destroy the main document context |
| 429 | */ |
| 430 | oldinput = ctxt->input; |
| 431 | oldinputNr = ctxt->inputNr; |
| 432 | oldinputMax = ctxt->inputMax; |
| 433 | oldinputTab = ctxt->inputTab; |
| 434 | oldcharset = ctxt->charset; |
| 435 | |
| 436 | ctxt->inputTab = (xmlParserInputPtr *) |
| 437 | xmlMalloc(5 * sizeof(xmlParserInputPtr)); |
| 438 | if (ctxt->inputTab == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 439 | xmlSAX2ErrMemory(ctxt, "xmlSAX2ExternalSubset"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 440 | ctxt->input = oldinput; |
| 441 | ctxt->inputNr = oldinputNr; |
| 442 | ctxt->inputMax = oldinputMax; |
| 443 | ctxt->inputTab = oldinputTab; |
| 444 | ctxt->charset = oldcharset; |
| 445 | return; |
| 446 | } |
| 447 | ctxt->inputNr = 0; |
| 448 | ctxt->inputMax = 5; |
| 449 | ctxt->input = NULL; |
| 450 | xmlPushInput(ctxt, input); |
| 451 | |
| 452 | /* |
| 453 | * On the fly encoding conversion if needed |
| 454 | */ |
| 455 | if (ctxt->input->length >= 4) { |
| 456 | enc = xmlDetectCharEncoding(ctxt->input->cur, 4); |
| 457 | xmlSwitchEncoding(ctxt, enc); |
| 458 | } |
| 459 | |
| 460 | if (input->filename == NULL) |
| 461 | input->filename = (char *) xmlCanonicPath(SystemID); |
| 462 | input->line = 1; |
| 463 | input->col = 1; |
| 464 | input->base = ctxt->input->cur; |
| 465 | input->cur = ctxt->input->cur; |
| 466 | input->free = NULL; |
| 467 | |
| 468 | /* |
| 469 | * let's parse that entity knowing it's an external subset. |
| 470 | */ |
| 471 | xmlParseExternalSubset(ctxt, ExternalID, SystemID); |
| 472 | |
| 473 | /* |
| 474 | * Free up the external entities |
| 475 | */ |
| 476 | |
| 477 | while (ctxt->inputNr > 1) |
| 478 | xmlPopInput(ctxt); |
| 479 | xmlFreeInputStream(ctxt->input); |
| 480 | xmlFree(ctxt->inputTab); |
| 481 | |
| 482 | /* |
| 483 | * Restore the parsing context of the main entity |
| 484 | */ |
| 485 | ctxt->input = oldinput; |
| 486 | ctxt->inputNr = oldinputNr; |
| 487 | ctxt->inputMax = oldinputMax; |
| 488 | ctxt->inputTab = oldinputTab; |
| 489 | ctxt->charset = oldcharset; |
| 490 | /* ctxt->wellFormed = oldwellFormed; */ |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * xmlSAX2ResolveEntity: |
| 496 | * @ctx: the user data (XML parser context) |
| 497 | * @publicId: The public ID of the entity |
| 498 | * @systemId: The system ID of the entity |
| 499 | * |
| 500 | * The entity loader, to control the loading of external entities, |
| 501 | * the application can either: |
| 502 | * - override this xmlSAX2ResolveEntity() callback in the SAX block |
| 503 | * - or better use the xmlSetExternalEntityLoader() function to |
| 504 | * set up it's own entity resolution routine |
| 505 | * |
| 506 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 507 | */ |
| 508 | xmlParserInputPtr |
| 509 | xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId) |
| 510 | { |
| 511 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 512 | xmlParserInputPtr ret; |
| 513 | xmlChar *URI; |
| 514 | const char *base = NULL; |
| 515 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 516 | if (ctx == NULL) return(NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 517 | if (ctxt->input != NULL) |
| 518 | base = ctxt->input->filename; |
| 519 | if (base == NULL) |
| 520 | base = ctxt->directory; |
| 521 | |
| 522 | URI = xmlBuildURI(systemId, (const xmlChar *) base); |
| 523 | |
| 524 | #ifdef DEBUG_SAX |
| 525 | xmlGenericError(xmlGenericErrorContext, |
| 526 | "SAX.xmlSAX2ResolveEntity(%s, %s)\n", publicId, systemId); |
| 527 | #endif |
| 528 | |
| 529 | ret = xmlLoadExternalEntity((const char *) URI, |
| 530 | (const char *) publicId, ctxt); |
| 531 | if (URI != NULL) |
| 532 | xmlFree(URI); |
| 533 | return(ret); |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * xmlSAX2GetEntity: |
| 538 | * @ctx: the user data (XML parser context) |
| 539 | * @name: The entity name |
| 540 | * |
| 541 | * Get an entity by name |
| 542 | * |
| 543 | * Returns the xmlEntityPtr if found. |
| 544 | */ |
| 545 | xmlEntityPtr |
| 546 | xmlSAX2GetEntity(void *ctx, const xmlChar *name) |
| 547 | { |
| 548 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 549 | xmlEntityPtr ret = NULL; |
| 550 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 551 | if (ctx == NULL) return(NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 552 | #ifdef DEBUG_SAX |
| 553 | xmlGenericError(xmlGenericErrorContext, |
| 554 | "SAX.xmlSAX2GetEntity(%s)\n", name); |
| 555 | #endif |
| 556 | |
| 557 | if (ctxt->inSubset == 0) { |
| 558 | ret = xmlGetPredefinedEntity(name); |
| 559 | if (ret != NULL) |
| 560 | return(ret); |
| 561 | } |
| 562 | if ((ctxt->myDoc != NULL) && (ctxt->myDoc->standalone == 1)) { |
| 563 | if (ctxt->inSubset == 2) { |
| 564 | ctxt->myDoc->standalone = 0; |
| 565 | ret = xmlGetDocEntity(ctxt->myDoc, name); |
| 566 | ctxt->myDoc->standalone = 1; |
| 567 | } else { |
| 568 | ret = xmlGetDocEntity(ctxt->myDoc, name); |
| 569 | if (ret == NULL) { |
| 570 | ctxt->myDoc->standalone = 0; |
| 571 | ret = xmlGetDocEntity(ctxt->myDoc, name); |
| 572 | if (ret != NULL) { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 573 | xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE, |
| 574 | "Entity(%s) document marked standalone but requires external subset\n", |
| 575 | name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 576 | } |
| 577 | ctxt->myDoc->standalone = 1; |
| 578 | } |
| 579 | } |
| 580 | } else { |
| 581 | ret = xmlGetDocEntity(ctxt->myDoc, name); |
| 582 | } |
| 583 | if ((ret != NULL) && |
| 584 | ((ctxt->validate) || (ctxt->replaceEntities)) && |
| 585 | (ret->children == NULL) && |
| 586 | (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { |
| 587 | int val; |
| 588 | |
| 589 | /* |
| 590 | * for validation purposes we really need to fetch and |
| 591 | * parse the external entity |
| 592 | */ |
| 593 | xmlNodePtr children; |
| 594 | |
| 595 | val = xmlParseCtxtExternalEntity(ctxt, ret->URI, |
| 596 | ret->ExternalID, &children); |
| 597 | if (val == 0) { |
| 598 | xmlAddChildList((xmlNodePtr) ret, children); |
| 599 | } else { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 600 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING, |
| 601 | "Failure to process entity %s\n", name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 602 | ctxt->validate = 0; |
| 603 | return(NULL); |
| 604 | } |
| 605 | ret->owner = 1; |
Daniel Veillard | f4f4e48 | 2008-08-25 08:57:48 +0000 | [diff] [blame] | 606 | if (ret->checked == 0) |
| 607 | ret->checked = 1; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 608 | } |
| 609 | return(ret); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * xmlSAX2GetParameterEntity: |
| 614 | * @ctx: the user data (XML parser context) |
| 615 | * @name: The entity name |
| 616 | * |
| 617 | * Get a parameter entity by name |
| 618 | * |
| 619 | * Returns the xmlEntityPtr if found. |
| 620 | */ |
| 621 | xmlEntityPtr |
| 622 | xmlSAX2GetParameterEntity(void *ctx, const xmlChar *name) |
| 623 | { |
| 624 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 625 | xmlEntityPtr ret; |
| 626 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 627 | if (ctx == NULL) return(NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 628 | #ifdef DEBUG_SAX |
| 629 | xmlGenericError(xmlGenericErrorContext, |
| 630 | "SAX.xmlSAX2GetParameterEntity(%s)\n", name); |
| 631 | #endif |
| 632 | |
| 633 | ret = xmlGetParameterEntity(ctxt->myDoc, name); |
| 634 | return(ret); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /** |
| 639 | * xmlSAX2EntityDecl: |
| 640 | * @ctx: the user data (XML parser context) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 641 | * @name: the entity name |
| 642 | * @type: the entity type |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 643 | * @publicId: The public ID of the entity |
| 644 | * @systemId: The system ID of the entity |
| 645 | * @content: the entity value (without processing). |
| 646 | * |
| 647 | * An entity definition has been parsed |
| 648 | */ |
| 649 | void |
| 650 | xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type, |
| 651 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
| 652 | { |
| 653 | xmlEntityPtr ent; |
| 654 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 655 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 656 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 657 | #ifdef DEBUG_SAX |
| 658 | xmlGenericError(xmlGenericErrorContext, |
| 659 | "SAX.xmlSAX2EntityDecl(%s, %d, %s, %s, %s)\n", |
| 660 | name, type, publicId, systemId, content); |
| 661 | #endif |
| 662 | if (ctxt->inSubset == 1) { |
| 663 | ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId, |
| 664 | systemId, content); |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 665 | if ((ent == NULL) && (ctxt->pedantic)) |
| 666 | xmlWarnMsg(ctxt, XML_WAR_ENTITY_REDEFINED, |
| 667 | "Entity(%s) already defined in the internal subset\n", |
| 668 | name); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 669 | if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) { |
| 670 | xmlChar *URI; |
| 671 | const char *base = NULL; |
| 672 | |
| 673 | if (ctxt->input != NULL) |
| 674 | base = ctxt->input->filename; |
| 675 | if (base == NULL) |
| 676 | base = ctxt->directory; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 677 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 678 | URI = xmlBuildURI(systemId, (const xmlChar *) base); |
| 679 | ent->URI = URI; |
| 680 | } |
| 681 | } else if (ctxt->inSubset == 2) { |
| 682 | ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId, |
| 683 | systemId, content); |
| 684 | if ((ent == NULL) && (ctxt->pedantic) && |
| 685 | (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 686 | ctxt->sax->warning(ctxt->userData, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 687 | "Entity(%s) already defined in the external subset\n", name); |
| 688 | if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) { |
| 689 | xmlChar *URI; |
| 690 | const char *base = NULL; |
| 691 | |
| 692 | if (ctxt->input != NULL) |
| 693 | base = ctxt->input->filename; |
| 694 | if (base == NULL) |
| 695 | base = ctxt->directory; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 696 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 697 | URI = xmlBuildURI(systemId, (const xmlChar *) base); |
| 698 | ent->URI = URI; |
| 699 | } |
| 700 | } else { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 701 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING, |
| 702 | "SAX.xmlSAX2EntityDecl(%s) called while not in subset\n", |
| 703 | name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * xmlSAX2AttributeDecl: |
| 709 | * @ctx: the user data (XML parser context) |
| 710 | * @elem: the name of the element |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 711 | * @fullname: the attribute name |
| 712 | * @type: the attribute type |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 713 | * @def: the type of default value |
| 714 | * @defaultValue: the attribute default value |
| 715 | * @tree: the tree of enumerated value set |
| 716 | * |
| 717 | * An attribute definition has been parsed |
| 718 | */ |
| 719 | void |
| 720 | xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, |
| 721 | int type, int def, const xmlChar *defaultValue, |
| 722 | xmlEnumerationPtr tree) |
| 723 | { |
| 724 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 725 | xmlAttributePtr attr; |
| 726 | xmlChar *name = NULL, *prefix = NULL; |
| 727 | |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 728 | if ((ctxt == NULL) || (ctxt->myDoc == NULL)) |
| 729 | return; |
| 730 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 731 | #ifdef DEBUG_SAX |
| 732 | xmlGenericError(xmlGenericErrorContext, |
| 733 | "SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n", |
| 734 | elem, fullname, type, def, defaultValue); |
| 735 | #endif |
Daniel Veillard | 68cb4b2 | 2004-04-18 20:55:39 +0000 | [diff] [blame] | 736 | if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) && |
| 737 | (type != XML_ATTRIBUTE_ID)) { |
| 738 | /* |
| 739 | * Raise the error but keep the validity flag |
| 740 | */ |
| 741 | int tmp = ctxt->valid; |
| 742 | xmlErrValid(ctxt, XML_DTD_XMLID_TYPE, |
| 743 | "xml:id : attribute type should be ID\n", NULL, NULL); |
| 744 | ctxt->valid = tmp; |
| 745 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 746 | /* TODO: optimize name/prefix allocation */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 747 | name = xmlSplitQName(ctxt, fullname, &prefix); |
| 748 | ctxt->vctxt.valid = 1; |
| 749 | if (ctxt->inSubset == 1) |
| 750 | attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem, |
| 751 | name, prefix, (xmlAttributeType) type, |
| 752 | (xmlAttributeDefault) def, defaultValue, tree); |
| 753 | else if (ctxt->inSubset == 2) |
| 754 | attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem, |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 755 | name, prefix, (xmlAttributeType) type, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 756 | (xmlAttributeDefault) def, defaultValue, tree); |
| 757 | else { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 758 | xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, |
| 759 | "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n", |
| 760 | name, NULL); |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 761 | xmlFreeEnumeration(tree); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 762 | return; |
| 763 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 764 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 765 | if (ctxt->vctxt.valid == 0) |
| 766 | ctxt->valid = 0; |
| 767 | if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) && |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 768 | (ctxt->myDoc->intSubset != NULL)) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 769 | ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, |
| 770 | attr); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 771 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 772 | if (prefix != NULL) |
| 773 | xmlFree(prefix); |
| 774 | if (name != NULL) |
| 775 | xmlFree(name); |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * xmlSAX2ElementDecl: |
| 780 | * @ctx: the user data (XML parser context) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 781 | * @name: the element name |
| 782 | * @type: the element type |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 783 | * @content: the element value tree |
| 784 | * |
| 785 | * An element definition has been parsed |
| 786 | */ |
| 787 | void |
| 788 | xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type, |
| 789 | xmlElementContentPtr content) |
| 790 | { |
| 791 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 792 | xmlElementPtr elem = NULL; |
| 793 | |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 794 | if ((ctxt == NULL) || (ctxt->myDoc == NULL)) |
| 795 | return; |
| 796 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 797 | #ifdef DEBUG_SAX |
| 798 | xmlGenericError(xmlGenericErrorContext, |
| 799 | "SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type); |
| 800 | #endif |
| 801 | |
| 802 | if (ctxt->inSubset == 1) |
| 803 | elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, |
| 804 | name, (xmlElementTypeVal) type, content); |
| 805 | else if (ctxt->inSubset == 2) |
| 806 | elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, |
| 807 | name, (xmlElementTypeVal) type, content); |
| 808 | else { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 809 | xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, |
| 810 | "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n", |
| 811 | name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 812 | return; |
| 813 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 814 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 815 | if (elem == NULL) |
| 816 | ctxt->valid = 0; |
| 817 | if (ctxt->validate && ctxt->wellFormed && |
| 818 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 819 | ctxt->valid &= |
| 820 | xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 821 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
| 825 | * xmlSAX2NotationDecl: |
| 826 | * @ctx: the user data (XML parser context) |
| 827 | * @name: The name of the notation |
| 828 | * @publicId: The public ID of the entity |
| 829 | * @systemId: The system ID of the entity |
| 830 | * |
| 831 | * What to do when a notation declaration has been parsed. |
| 832 | */ |
| 833 | void |
| 834 | xmlSAX2NotationDecl(void *ctx, const xmlChar *name, |
| 835 | const xmlChar *publicId, const xmlChar *systemId) |
| 836 | { |
| 837 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 838 | xmlNotationPtr nota = NULL; |
| 839 | |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 840 | if ((ctxt == NULL) || (ctxt->myDoc == NULL)) |
| 841 | return; |
| 842 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 843 | #ifdef DEBUG_SAX |
| 844 | xmlGenericError(xmlGenericErrorContext, |
| 845 | "SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId); |
| 846 | #endif |
| 847 | |
| 848 | if ((publicId == NULL) && (systemId == NULL)) { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 849 | xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING, |
| 850 | "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n", |
| 851 | name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 852 | return; |
| 853 | } else if (ctxt->inSubset == 1) |
| 854 | nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name, |
| 855 | publicId, systemId); |
| 856 | else if (ctxt->inSubset == 2) |
| 857 | nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name, |
| 858 | publicId, systemId); |
| 859 | else { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 860 | xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING, |
| 861 | "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n", |
| 862 | name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 863 | return; |
| 864 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 865 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 866 | if (nota == NULL) ctxt->valid = 0; |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 867 | if ((ctxt->validate) && (ctxt->wellFormed) && |
| 868 | (ctxt->myDoc->intSubset != NULL)) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 869 | ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc, |
| 870 | nota); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 871 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /** |
| 875 | * xmlSAX2UnparsedEntityDecl: |
| 876 | * @ctx: the user data (XML parser context) |
| 877 | * @name: The name of the entity |
| 878 | * @publicId: The public ID of the entity |
| 879 | * @systemId: The system ID of the entity |
| 880 | * @notationName: the name of the notation |
| 881 | * |
| 882 | * What to do when an unparsed entity declaration is parsed |
| 883 | */ |
| 884 | void |
| 885 | xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name, |
| 886 | const xmlChar *publicId, const xmlChar *systemId, |
| 887 | const xmlChar *notationName) |
| 888 | { |
| 889 | xmlEntityPtr ent; |
| 890 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 891 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 892 | #ifdef DEBUG_SAX |
| 893 | xmlGenericError(xmlGenericErrorContext, |
| 894 | "SAX.xmlSAX2UnparsedEntityDecl(%s, %s, %s, %s)\n", |
| 895 | name, publicId, systemId, notationName); |
| 896 | #endif |
| 897 | if (ctxt->inSubset == 1) { |
| 898 | ent = xmlAddDocEntity(ctxt->myDoc, name, |
| 899 | XML_EXTERNAL_GENERAL_UNPARSED_ENTITY, |
| 900 | publicId, systemId, notationName); |
| 901 | if ((ent == NULL) && (ctxt->pedantic) && |
| 902 | (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 903 | ctxt->sax->warning(ctxt->userData, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 904 | "Entity(%s) already defined in the internal subset\n", name); |
| 905 | if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) { |
| 906 | xmlChar *URI; |
| 907 | const char *base = NULL; |
| 908 | |
| 909 | if (ctxt->input != NULL) |
| 910 | base = ctxt->input->filename; |
| 911 | if (base == NULL) |
| 912 | base = ctxt->directory; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 913 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 914 | URI = xmlBuildURI(systemId, (const xmlChar *) base); |
| 915 | ent->URI = URI; |
| 916 | } |
| 917 | } else if (ctxt->inSubset == 2) { |
| 918 | ent = xmlAddDtdEntity(ctxt->myDoc, name, |
| 919 | XML_EXTERNAL_GENERAL_UNPARSED_ENTITY, |
| 920 | publicId, systemId, notationName); |
| 921 | if ((ent == NULL) && (ctxt->pedantic) && |
| 922 | (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 923 | ctxt->sax->warning(ctxt->userData, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 924 | "Entity(%s) already defined in the external subset\n", name); |
| 925 | if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) { |
| 926 | xmlChar *URI; |
| 927 | const char *base = NULL; |
| 928 | |
| 929 | if (ctxt->input != NULL) |
| 930 | base = ctxt->input->filename; |
| 931 | if (base == NULL) |
| 932 | base = ctxt->directory; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 933 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 934 | URI = xmlBuildURI(systemId, (const xmlChar *) base); |
| 935 | ent->URI = URI; |
| 936 | } |
| 937 | } else { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 938 | xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, |
| 939 | "SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n", |
| 940 | name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * xmlSAX2SetDocumentLocator: |
| 946 | * @ctx: the user data (XML parser context) |
| 947 | * @loc: A SAX Locator |
| 948 | * |
| 949 | * Receive the document locator at startup, actually xmlDefaultSAXLocator |
| 950 | * Everything is available on the context, so this is useless in our case. |
| 951 | */ |
| 952 | void |
| 953 | xmlSAX2SetDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED) |
| 954 | { |
| 955 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
| 956 | #ifdef DEBUG_SAX |
| 957 | xmlGenericError(xmlGenericErrorContext, |
| 958 | "SAX.xmlSAX2SetDocumentLocator()\n"); |
| 959 | #endif |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * xmlSAX2StartDocument: |
| 964 | * @ctx: the user data (XML parser context) |
| 965 | * |
| 966 | * called when the document start being processed. |
| 967 | */ |
| 968 | void |
| 969 | xmlSAX2StartDocument(void *ctx) |
| 970 | { |
| 971 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 972 | xmlDocPtr doc; |
| 973 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 974 | if (ctx == NULL) return; |
| 975 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 976 | #ifdef DEBUG_SAX |
| 977 | xmlGenericError(xmlGenericErrorContext, |
| 978 | "SAX.xmlSAX2StartDocument()\n"); |
| 979 | #endif |
| 980 | if (ctxt->html) { |
| 981 | #ifdef LIBXML_HTML_ENABLED |
| 982 | if (ctxt->myDoc == NULL) |
| 983 | ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL); |
Daniel Veillard | ae0765b | 2008-07-31 19:54:59 +0000 | [diff] [blame] | 984 | ctxt->myDoc->properties = XML_DOC_HTML; |
| 985 | ctxt->myDoc->parseFlags = ctxt->options; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 986 | if (ctxt->myDoc == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 987 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 988 | return; |
| 989 | } |
| 990 | #else |
| 991 | xmlGenericError(xmlGenericErrorContext, |
| 992 | "libxml2 built without HTML support\n"); |
| 993 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
| 994 | ctxt->instate = XML_PARSER_EOF; |
| 995 | ctxt->disableSAX = 1; |
| 996 | return; |
| 997 | #endif |
| 998 | } else { |
| 999 | doc = ctxt->myDoc = xmlNewDoc(ctxt->version); |
| 1000 | if (doc != NULL) { |
Daniel Veillard | ae0765b | 2008-07-31 19:54:59 +0000 | [diff] [blame] | 1001 | doc->properties = 0; |
| 1002 | if (ctxt->options & XML_PARSE_OLD10) |
| 1003 | doc->properties |= XML_DOC_OLD10; |
| 1004 | doc->parseFlags = ctxt->options; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1005 | if (ctxt->encoding != NULL) |
| 1006 | doc->encoding = xmlStrdup(ctxt->encoding); |
| 1007 | else |
| 1008 | doc->encoding = NULL; |
| 1009 | doc->standalone = ctxt->standalone; |
| 1010 | } else { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1011 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1012 | return; |
| 1013 | } |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 1014 | if ((ctxt->dictNames) && (doc != NULL)) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1015 | doc->dict = ctxt->dict; |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 1016 | xmlDictReference(doc->dict); |
| 1017 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1018 | } |
| 1019 | if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) && |
| 1020 | (ctxt->input != NULL) && (ctxt->input->filename != NULL)) { |
Daniel Veillard | b8efdda | 2006-10-10 12:37:14 +0000 | [diff] [blame] | 1021 | ctxt->myDoc->URL = xmlPathToURI((const xmlChar *)ctxt->input->filename); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1022 | if (ctxt->myDoc->URL == NULL) |
William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 1023 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * xmlSAX2EndDocument: |
| 1029 | * @ctx: the user data (XML parser context) |
| 1030 | * |
| 1031 | * called when the document end has been detected. |
| 1032 | */ |
| 1033 | void |
| 1034 | xmlSAX2EndDocument(void *ctx) |
| 1035 | { |
| 1036 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 1037 | #ifdef DEBUG_SAX |
| 1038 | xmlGenericError(xmlGenericErrorContext, |
| 1039 | "SAX.xmlSAX2EndDocument()\n"); |
| 1040 | #endif |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 1041 | if (ctx == NULL) return; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1042 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1043 | if (ctxt->validate && ctxt->wellFormed && |
| 1044 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 1045 | ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1046 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1047 | |
| 1048 | /* |
| 1049 | * Grab the encoding if it was added on-the-fly |
| 1050 | */ |
| 1051 | if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) && |
| 1052 | (ctxt->myDoc->encoding == NULL)) { |
| 1053 | ctxt->myDoc->encoding = ctxt->encoding; |
| 1054 | ctxt->encoding = NULL; |
| 1055 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 1056 | if ((ctxt->inputTab != NULL) && |
| 1057 | (ctxt->inputNr > 0) && (ctxt->inputTab[0] != NULL) && |
| 1058 | (ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) && |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1059 | (ctxt->myDoc->encoding == NULL)) { |
| 1060 | ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding); |
| 1061 | } |
| 1062 | if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) && |
| 1063 | (ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) { |
| 1064 | ctxt->myDoc->charset = ctxt->charset; |
| 1065 | } |
| 1066 | } |
| 1067 | |
Daniel Veillard | bca3ad2 | 2005-08-23 22:14:02 +0000 | [diff] [blame] | 1068 | #if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1069 | /** |
| 1070 | * xmlSAX2AttributeInternal: |
| 1071 | * @ctx: the user data (XML parser context) |
| 1072 | * @fullname: The attribute name, including namespace prefix |
| 1073 | * @value: The attribute value |
| 1074 | * @prefix: the prefix on the element node |
| 1075 | * |
| 1076 | * Handle an attribute that has been read by the parser. |
| 1077 | * The default handling is to convert the attribute into an |
| 1078 | * DOM subtree and past it in a new xmlAttr element added to |
| 1079 | * the element. |
| 1080 | */ |
| 1081 | static void |
| 1082 | xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1083 | const xmlChar *value, const xmlChar *prefix ATTRIBUTE_UNUSED) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1084 | { |
| 1085 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 1086 | xmlAttrPtr ret; |
| 1087 | xmlChar *name; |
| 1088 | xmlChar *ns; |
| 1089 | xmlChar *nval; |
| 1090 | xmlNsPtr namespace; |
| 1091 | |
Daniel Veillard | dbbd72b | 2007-06-12 15:15:52 +0000 | [diff] [blame] | 1092 | if (ctxt->html) { |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1093 | name = xmlStrdup(fullname); |
Daniel Veillard | dbbd72b | 2007-06-12 15:15:52 +0000 | [diff] [blame] | 1094 | ns = NULL; |
| 1095 | namespace = NULL; |
| 1096 | } else { |
| 1097 | /* |
| 1098 | * Split the full name into a namespace prefix and the tag name |
| 1099 | */ |
| 1100 | name = xmlSplitQName(ctxt, fullname, &ns); |
| 1101 | if ((name != NULL) && (name[0] == 0)) { |
| 1102 | if (xmlStrEqual(ns, BAD_CAST "xmlns")) { |
| 1103 | xmlNsErrMsg(ctxt, XML_ERR_NS_DECL_ERROR, |
| 1104 | "invalid namespace declaration '%s'\n", |
| 1105 | fullname, NULL); |
| 1106 | } else { |
| 1107 | xmlNsWarnMsg(ctxt, XML_WAR_NS_COLUMN, |
| 1108 | "Avoid attribute ending with ':' like '%s'\n", |
| 1109 | fullname, NULL); |
| 1110 | } |
| 1111 | if (ns != NULL) |
| 1112 | xmlFree(ns); |
| 1113 | ns = NULL; |
| 1114 | xmlFree(name); |
| 1115 | name = xmlStrdup(fullname); |
| 1116 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1117 | } |
| 1118 | if (name == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1119 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1120 | if (ns != NULL) |
| 1121 | xmlFree(ns); |
| 1122 | return; |
| 1123 | } |
| 1124 | |
Daniel Veillard | 3c080d6 | 2010-03-15 15:47:50 +0100 | [diff] [blame] | 1125 | #ifdef LIBXML_HTML_ENABLED |
| 1126 | if ((ctxt->html) && |
| 1127 | (value == NULL) && (htmlIsBooleanAttr(fullname))) { |
Daniel Veillard | 06c93b7 | 2010-03-15 16:08:44 +0100 | [diff] [blame] | 1128 | nval = xmlStrdup(fullname); |
| 1129 | value = (const xmlChar *) nval; |
Daniel Veillard | 3c080d6 | 2010-03-15 15:47:50 +0100 | [diff] [blame] | 1130 | } else |
| 1131 | #endif |
| 1132 | { |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1133 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 3c080d6 | 2010-03-15 15:47:50 +0100 | [diff] [blame] | 1134 | /* |
| 1135 | * Do the last stage of the attribute normalization |
| 1136 | * Needed for HTML too: |
| 1137 | * http://www.w3.org/TR/html4/types.html#h-6.2 |
| 1138 | */ |
| 1139 | ctxt->vctxt.valid = 1; |
| 1140 | nval = xmlValidCtxtNormalizeAttributeValue(&ctxt->vctxt, |
| 1141 | ctxt->myDoc, ctxt->node, |
| 1142 | fullname, value); |
| 1143 | if (ctxt->vctxt.valid != 1) { |
| 1144 | ctxt->valid = 0; |
| 1145 | } |
| 1146 | if (nval != NULL) |
| 1147 | value = nval; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1148 | #else |
Daniel Veillard | 3c080d6 | 2010-03-15 15:47:50 +0100 | [diff] [blame] | 1149 | nval = NULL; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1150 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 3c080d6 | 2010-03-15 15:47:50 +0100 | [diff] [blame] | 1151 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1152 | |
| 1153 | /* |
| 1154 | * Check whether it's a namespace definition |
| 1155 | */ |
| 1156 | if ((!ctxt->html) && (ns == NULL) && |
| 1157 | (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') && |
| 1158 | (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) { |
| 1159 | xmlNsPtr nsret; |
| 1160 | xmlChar *val; |
| 1161 | |
| 1162 | if (!ctxt->replaceEntities) { |
| 1163 | ctxt->depth++; |
| 1164 | val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF, |
| 1165 | 0,0,0); |
| 1166 | ctxt->depth--; |
| 1167 | } else { |
| 1168 | val = (xmlChar *) value; |
| 1169 | } |
| 1170 | |
| 1171 | if (val[0] != 0) { |
| 1172 | xmlURIPtr uri; |
| 1173 | |
| 1174 | uri = xmlParseURI((const char *)val); |
| 1175 | if (uri == NULL) { |
| 1176 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1177 | ctxt->sax->warning(ctxt->userData, |
William M. Brack | 4811ba3 | 2003-09-06 18:02:53 +0000 | [diff] [blame] | 1178 | "xmlns: %s not a valid URI\n", val); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1179 | } else { |
| 1180 | if (uri->scheme == NULL) { |
| 1181 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1182 | ctxt->sax->warning(ctxt->userData, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1183 | "xmlns: URI %s is not absolute\n", val); |
| 1184 | } |
| 1185 | xmlFreeURI(uri); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /* a default namespace definition */ |
| 1190 | nsret = xmlNewNs(ctxt->node, val, NULL); |
| 1191 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1192 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1193 | /* |
| 1194 | * Validate also for namespace decls, they are attributes from |
| 1195 | * an XML-1.0 perspective |
| 1196 | */ |
| 1197 | if (nsret != NULL && ctxt->validate && ctxt->wellFormed && |
| 1198 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 1199 | ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc, |
| 1200 | ctxt->node, prefix, nsret, val); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1201 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1202 | if (name != NULL) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1203 | xmlFree(name); |
| 1204 | if (nval != NULL) |
| 1205 | xmlFree(nval); |
| 1206 | if (val != value) |
| 1207 | xmlFree(val); |
| 1208 | return; |
| 1209 | } |
| 1210 | if ((!ctxt->html) && |
| 1211 | (ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') && |
| 1212 | (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) { |
| 1213 | xmlNsPtr nsret; |
| 1214 | xmlChar *val; |
| 1215 | |
| 1216 | if (!ctxt->replaceEntities) { |
| 1217 | ctxt->depth++; |
| 1218 | val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF, |
| 1219 | 0,0,0); |
| 1220 | ctxt->depth--; |
| 1221 | if (val == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1222 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1223 | xmlFree(ns); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1224 | if (name != NULL) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1225 | xmlFree(name); |
| 1226 | return; |
| 1227 | } |
| 1228 | } else { |
| 1229 | val = (xmlChar *) value; |
| 1230 | } |
| 1231 | |
| 1232 | if (val[0] == 0) { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 1233 | xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY, |
| 1234 | "Empty namespace name for prefix %s\n", name, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1235 | } |
| 1236 | if ((ctxt->pedantic != 0) && (val[0] != 0)) { |
| 1237 | xmlURIPtr uri; |
| 1238 | |
| 1239 | uri = xmlParseURI((const char *)val); |
| 1240 | if (uri == NULL) { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 1241 | xmlNsWarnMsg(ctxt, XML_WAR_NS_URI, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1242 | "xmlns:%s: %s not a valid URI\n", name, value); |
| 1243 | } else { |
| 1244 | if (uri->scheme == NULL) { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 1245 | xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1246 | "xmlns:%s: URI %s is not absolute\n", name, value); |
| 1247 | } |
| 1248 | xmlFreeURI(uri); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | /* a standard namespace definition */ |
| 1253 | nsret = xmlNewNs(ctxt->node, val, name); |
| 1254 | xmlFree(ns); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1255 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1256 | /* |
| 1257 | * Validate also for namespace decls, they are attributes from |
| 1258 | * an XML-1.0 perspective |
| 1259 | */ |
| 1260 | if (nsret != NULL && ctxt->validate && ctxt->wellFormed && |
| 1261 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 1262 | ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc, |
| 1263 | ctxt->node, prefix, nsret, value); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1264 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1265 | if (name != NULL) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1266 | xmlFree(name); |
| 1267 | if (nval != NULL) |
| 1268 | xmlFree(nval); |
| 1269 | if (val != value) |
| 1270 | xmlFree(val); |
| 1271 | return; |
| 1272 | } |
| 1273 | |
| 1274 | if (ns != NULL) { |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1275 | namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns); |
Daniel Veillard | d44b936 | 2009-09-07 12:15:08 +0200 | [diff] [blame] | 1276 | |
Daniel Veillard | 6790694 | 2003-08-28 21:13:25 +0000 | [diff] [blame] | 1277 | if (namespace == NULL) { |
Daniel Veillard | 87b3046 | 2005-07-05 14:04:36 +0000 | [diff] [blame] | 1278 | xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
William M. Brack | 4811ba3 | 2003-09-06 18:02:53 +0000 | [diff] [blame] | 1279 | "Namespace prefix %s of attribute %s is not defined\n", |
Daniel Veillard | 6790694 | 2003-08-28 21:13:25 +0000 | [diff] [blame] | 1280 | ns, name); |
Daniel Veillard | d44b936 | 2009-09-07 12:15:08 +0200 | [diff] [blame] | 1281 | } else { |
| 1282 | xmlAttrPtr prop; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1283 | |
Daniel Veillard | d44b936 | 2009-09-07 12:15:08 +0200 | [diff] [blame] | 1284 | prop = ctxt->node->properties; |
| 1285 | while (prop != NULL) { |
| 1286 | if (prop->ns != NULL) { |
| 1287 | if ((xmlStrEqual(name, prop->name)) && |
| 1288 | ((namespace == prop->ns) || |
| 1289 | (xmlStrEqual(namespace->href, prop->ns->href)))) { |
| 1290 | xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED, |
| 1291 | "Attribute %s in %s redefined\n", |
| 1292 | name, namespace->href); |
| 1293 | ctxt->wellFormed = 0; |
| 1294 | if (ctxt->recovery == 0) ctxt->disableSAX = 1; |
| 1295 | goto error; |
| 1296 | } |
| 1297 | } |
| 1298 | prop = prop->next; |
| 1299 | } |
| 1300 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1301 | } else { |
| 1302 | namespace = NULL; |
| 1303 | } |
| 1304 | |
| 1305 | /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */ |
| 1306 | ret = xmlNewNsPropEatName(ctxt->node, namespace, name, NULL); |
| 1307 | |
| 1308 | if (ret != NULL) { |
| 1309 | if ((ctxt->replaceEntities == 0) && (!ctxt->html)) { |
| 1310 | xmlNodePtr tmp; |
| 1311 | |
| 1312 | ret->children = xmlStringGetNodeList(ctxt->myDoc, value); |
| 1313 | tmp = ret->children; |
| 1314 | while (tmp != NULL) { |
| 1315 | tmp->parent = (xmlNodePtr) ret; |
| 1316 | if (tmp->next == NULL) |
| 1317 | ret->last = tmp; |
| 1318 | tmp = tmp->next; |
| 1319 | } |
| 1320 | } else if (value != NULL) { |
| 1321 | ret->children = xmlNewDocText(ctxt->myDoc, value); |
| 1322 | ret->last = ret->children; |
| 1323 | if (ret->children != NULL) |
| 1324 | ret->children->parent = (xmlNodePtr) ret; |
| 1325 | } |
| 1326 | } |
| 1327 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1328 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1329 | if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && |
| 1330 | ctxt->myDoc && ctxt->myDoc->intSubset) { |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1331 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1332 | /* |
| 1333 | * If we don't substitute entities, the validation should be |
| 1334 | * done on a value with replaced entities anyway. |
| 1335 | */ |
| 1336 | if (!ctxt->replaceEntities) { |
| 1337 | xmlChar *val; |
| 1338 | |
| 1339 | ctxt->depth++; |
| 1340 | val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF, |
| 1341 | 0,0,0); |
| 1342 | ctxt->depth--; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1343 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1344 | if (val == NULL) |
| 1345 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 1346 | ctxt->myDoc, ctxt->node, ret, value); |
| 1347 | else { |
| 1348 | xmlChar *nvalnorm; |
| 1349 | |
| 1350 | /* |
| 1351 | * Do the last stage of the attribute normalization |
| 1352 | * It need to be done twice ... it's an extra burden related |
| 1353 | * to the ability to keep xmlSAX2References in attributes |
| 1354 | */ |
| 1355 | nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc, |
| 1356 | ctxt->node, fullname, val); |
| 1357 | if (nvalnorm != NULL) { |
| 1358 | xmlFree(val); |
| 1359 | val = nvalnorm; |
| 1360 | } |
| 1361 | |
| 1362 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 1363 | ctxt->myDoc, ctxt->node, ret, val); |
| 1364 | xmlFree(val); |
| 1365 | } |
| 1366 | } else { |
| 1367 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc, |
| 1368 | ctxt->node, ret, value); |
| 1369 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1370 | } else |
| 1371 | #endif /* LIBXML_VALID_ENABLED */ |
| 1372 | if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) && |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1373 | (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) || |
| 1374 | ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) { |
| 1375 | /* |
| 1376 | * when validating, the ID registration is done at the attribute |
| 1377 | * validation level. Otherwise we have to do specific handling here. |
| 1378 | */ |
Daniel Veillard | 54f9a4f | 2005-09-03 13:28:24 +0000 | [diff] [blame] | 1379 | if (xmlStrEqual(fullname, BAD_CAST "xml:id")) { |
Daniel Veillard | 67f8b1c | 2004-04-09 21:51:49 +0000 | [diff] [blame] | 1380 | /* |
| 1381 | * Add the xml:id value |
| 1382 | * |
| 1383 | * Open issue: normalization of the value. |
| 1384 | */ |
Daniel Veillard | 68cb4b2 | 2004-04-18 20:55:39 +0000 | [diff] [blame] | 1385 | if (xmlValidateNCName(value, 1) != 0) { |
| 1386 | xmlErrValid(ctxt, XML_DTD_XMLID_VALUE, |
| 1387 | "xml:id : attribute value %s is not an NCName\n", |
| 1388 | (const char *) value, NULL); |
| 1389 | } |
Daniel Veillard | 67f8b1c | 2004-04-09 21:51:49 +0000 | [diff] [blame] | 1390 | xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); |
Daniel Veillard | 54f9a4f | 2005-09-03 13:28:24 +0000 | [diff] [blame] | 1391 | } else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) |
| 1392 | xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); |
| 1393 | else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) |
| 1394 | xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | error: |
| 1398 | if (nval != NULL) |
| 1399 | xmlFree(nval); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1400 | if (ns != NULL) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1401 | xmlFree(ns); |
| 1402 | } |
| 1403 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1404 | /* |
| 1405 | * xmlCheckDefaultedAttributes: |
| 1406 | * |
| 1407 | * Check defaulted attributes from the DTD |
| 1408 | */ |
| 1409 | static void |
| 1410 | xmlCheckDefaultedAttributes(xmlParserCtxtPtr ctxt, const xmlChar *name, |
| 1411 | const xmlChar *prefix, const xmlChar **atts) { |
| 1412 | xmlElementPtr elemDecl; |
| 1413 | const xmlChar *att; |
| 1414 | int internal = 1; |
| 1415 | int i; |
| 1416 | |
| 1417 | elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset, name, prefix); |
| 1418 | if (elemDecl == NULL) { |
| 1419 | elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, name, prefix); |
| 1420 | internal = 0; |
| 1421 | } |
| 1422 | |
| 1423 | process_external_subset: |
| 1424 | |
| 1425 | if (elemDecl != NULL) { |
| 1426 | xmlAttributePtr attr = elemDecl->attributes; |
| 1427 | /* |
| 1428 | * Check against defaulted attributes from the external subset |
| 1429 | * if the document is stamped as standalone |
| 1430 | */ |
| 1431 | if ((ctxt->myDoc->standalone == 1) && |
| 1432 | (ctxt->myDoc->extSubset != NULL) && |
| 1433 | (ctxt->validate)) { |
| 1434 | while (attr != NULL) { |
| 1435 | if ((attr->defaultValue != NULL) && |
| 1436 | (xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset, |
| 1437 | attr->elem, attr->name, |
| 1438 | attr->prefix) == attr) && |
| 1439 | (xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset, |
| 1440 | attr->elem, attr->name, |
| 1441 | attr->prefix) == NULL)) { |
| 1442 | xmlChar *fulln; |
| 1443 | |
| 1444 | if (attr->prefix != NULL) { |
| 1445 | fulln = xmlStrdup(attr->prefix); |
| 1446 | fulln = xmlStrcat(fulln, BAD_CAST ":"); |
| 1447 | fulln = xmlStrcat(fulln, attr->name); |
| 1448 | } else { |
| 1449 | fulln = xmlStrdup(attr->name); |
| 1450 | } |
Jim Meyering | 669e88c | 2009-07-29 11:33:32 +0200 | [diff] [blame] | 1451 | if (fulln == NULL) { |
| 1452 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
| 1453 | break; |
| 1454 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1455 | |
| 1456 | /* |
| 1457 | * Check that the attribute is not declared in the |
| 1458 | * serialization |
| 1459 | */ |
| 1460 | att = NULL; |
| 1461 | if (atts != NULL) { |
| 1462 | i = 0; |
| 1463 | att = atts[i]; |
| 1464 | while (att != NULL) { |
| 1465 | if (xmlStrEqual(att, fulln)) |
| 1466 | break; |
| 1467 | i += 2; |
| 1468 | att = atts[i]; |
| 1469 | } |
| 1470 | } |
| 1471 | if (att == NULL) { |
Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 1472 | xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED, |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1473 | "standalone: attribute %s on %s defaulted from external subset\n", |
Daniel Veillard | 427174f | 2003-12-10 10:42:59 +0000 | [diff] [blame] | 1474 | (const char *)fulln, |
| 1475 | (const char *)attr->elem); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1476 | } |
Daniel Veillard | 023d0ba | 2009-07-29 11:34:50 +0200 | [diff] [blame] | 1477 | xmlFree(fulln); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1478 | } |
| 1479 | attr = attr->nexth; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | /* |
| 1484 | * Actually insert defaulted values when needed |
| 1485 | */ |
| 1486 | attr = elemDecl->attributes; |
| 1487 | while (attr != NULL) { |
| 1488 | /* |
| 1489 | * Make sure that attributes redefinition occuring in the |
| 1490 | * internal subset are not overriden by definitions in the |
| 1491 | * external subset. |
| 1492 | */ |
| 1493 | if (attr->defaultValue != NULL) { |
| 1494 | /* |
| 1495 | * the element should be instantiated in the tree if: |
| 1496 | * - this is a namespace prefix |
| 1497 | * - the user required for completion in the tree |
| 1498 | * like XSLT |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1499 | * - there isn't already an attribute definition |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1500 | * in the internal subset overriding it. |
| 1501 | */ |
| 1502 | if (((attr->prefix != NULL) && |
| 1503 | (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) || |
| 1504 | ((attr->prefix == NULL) && |
| 1505 | (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) || |
| 1506 | (ctxt->loadsubset & XML_COMPLETE_ATTRS)) { |
| 1507 | xmlAttributePtr tst; |
| 1508 | |
| 1509 | tst = xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset, |
| 1510 | attr->elem, attr->name, |
| 1511 | attr->prefix); |
| 1512 | if ((tst == attr) || (tst == NULL)) { |
| 1513 | xmlChar fn[50]; |
| 1514 | xmlChar *fulln; |
| 1515 | |
| 1516 | fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50); |
| 1517 | if (fulln == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1518 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | * Check that the attribute is not declared in the |
| 1524 | * serialization |
| 1525 | */ |
| 1526 | att = NULL; |
| 1527 | if (atts != NULL) { |
| 1528 | i = 0; |
| 1529 | att = atts[i]; |
| 1530 | while (att != NULL) { |
| 1531 | if (xmlStrEqual(att, fulln)) |
| 1532 | break; |
| 1533 | i += 2; |
| 1534 | att = atts[i]; |
| 1535 | } |
| 1536 | } |
| 1537 | if (att == NULL) { |
| 1538 | xmlSAX2AttributeInternal(ctxt, fulln, |
| 1539 | attr->defaultValue, prefix); |
| 1540 | } |
| 1541 | if ((fulln != fn) && (fulln != attr->name)) |
| 1542 | xmlFree(fulln); |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | attr = attr->nexth; |
| 1547 | } |
| 1548 | if (internal == 1) { |
| 1549 | elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, |
| 1550 | name, prefix); |
| 1551 | internal = 0; |
| 1552 | goto process_external_subset; |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * xmlSAX2StartElement: |
| 1559 | * @ctx: the user data (XML parser context) |
| 1560 | * @fullname: The element name, including namespace prefix |
| 1561 | * @atts: An array of name/value attributes pairs, NULL terminated |
| 1562 | * |
| 1563 | * called when an opening tag has been processed. |
| 1564 | */ |
| 1565 | void |
| 1566 | xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) |
| 1567 | { |
| 1568 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 1569 | xmlNodePtr ret; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1570 | xmlNodePtr parent; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1571 | xmlNsPtr ns; |
| 1572 | xmlChar *name; |
| 1573 | xmlChar *prefix; |
| 1574 | const xmlChar *att; |
| 1575 | const xmlChar *value; |
| 1576 | int i; |
| 1577 | |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 1578 | if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1579 | parent = ctxt->node; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1580 | #ifdef DEBUG_SAX |
| 1581 | xmlGenericError(xmlGenericErrorContext, |
| 1582 | "SAX.xmlSAX2StartElement(%s)\n", fullname); |
| 1583 | #endif |
| 1584 | |
| 1585 | /* |
| 1586 | * First check on validity: |
| 1587 | */ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1588 | if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1589 | ((ctxt->myDoc->intSubset == NULL) || |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1590 | ((ctxt->myDoc->intSubset->notations == NULL) && |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1591 | (ctxt->myDoc->intSubset->elements == NULL) && |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1592 | (ctxt->myDoc->intSubset->attributes == NULL) && |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1593 | (ctxt->myDoc->intSubset->entities == NULL)))) { |
Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 1594 | xmlErrValid(ctxt, XML_ERR_NO_DTD, |
| 1595 | "Validation failed: no DTD found !", NULL, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1596 | ctxt->validate = 0; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1597 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1598 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1599 | |
| 1600 | /* |
| 1601 | * Split the full name into a namespace prefix and the tag name |
| 1602 | */ |
| 1603 | name = xmlSplitQName(ctxt, fullname, &prefix); |
| 1604 | |
| 1605 | |
| 1606 | /* |
| 1607 | * Note : the namespace resolution is deferred until the end of the |
| 1608 | * attributes parsing, since local namespace can be defined as |
| 1609 | * an attribute at this level. |
| 1610 | */ |
| 1611 | ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, name, NULL); |
| 1612 | if (ret == NULL) { |
| 1613 | if (prefix != NULL) |
| 1614 | xmlFree(prefix); |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1615 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1616 | return; |
| 1617 | } |
| 1618 | if (ctxt->myDoc->children == NULL) { |
| 1619 | #ifdef DEBUG_SAX_TREE |
| 1620 | xmlGenericError(xmlGenericErrorContext, "Setting %s as root\n", name); |
| 1621 | #endif |
| 1622 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
| 1623 | } else if (parent == NULL) { |
| 1624 | parent = ctxt->myDoc->children; |
| 1625 | } |
| 1626 | ctxt->nodemem = -1; |
| 1627 | if (ctxt->linenumbers) { |
Daniel Veillard | 3e35f8e | 2003-10-21 00:05:38 +0000 | [diff] [blame] | 1628 | if (ctxt->input != NULL) { |
| 1629 | if (ctxt->input->line < 65535) |
| 1630 | ret->line = (short) ctxt->input->line; |
| 1631 | else |
| 1632 | ret->line = 65535; |
| 1633 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /* |
| 1637 | * We are parsing a new node. |
| 1638 | */ |
| 1639 | #ifdef DEBUG_SAX_TREE |
| 1640 | xmlGenericError(xmlGenericErrorContext, "pushing(%s)\n", name); |
| 1641 | #endif |
| 1642 | nodePush(ctxt, ret); |
| 1643 | |
| 1644 | /* |
| 1645 | * Link the child element |
| 1646 | */ |
| 1647 | if (parent != NULL) { |
| 1648 | if (parent->type == XML_ELEMENT_NODE) { |
| 1649 | #ifdef DEBUG_SAX_TREE |
| 1650 | xmlGenericError(xmlGenericErrorContext, |
| 1651 | "adding child %s to %s\n", name, parent->name); |
| 1652 | #endif |
| 1653 | xmlAddChild(parent, ret); |
| 1654 | } else { |
| 1655 | #ifdef DEBUG_SAX_TREE |
| 1656 | xmlGenericError(xmlGenericErrorContext, |
| 1657 | "adding sibling %s to ", name); |
| 1658 | xmlDebugDumpOneNode(stderr, parent, 0); |
| 1659 | #endif |
| 1660 | xmlAddSibling(parent, ret); |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | /* |
| 1665 | * Insert all the defaulted attributes from the DTD especially namespaces |
| 1666 | */ |
| 1667 | if ((!ctxt->html) && |
| 1668 | ((ctxt->myDoc->intSubset != NULL) || |
| 1669 | (ctxt->myDoc->extSubset != NULL))) { |
| 1670 | xmlCheckDefaultedAttributes(ctxt, name, prefix, atts); |
| 1671 | } |
| 1672 | |
| 1673 | /* |
| 1674 | * process all the attributes whose name start with "xmlns" |
| 1675 | */ |
| 1676 | if (atts != NULL) { |
| 1677 | i = 0; |
| 1678 | att = atts[i++]; |
| 1679 | value = atts[i++]; |
| 1680 | if (!ctxt->html) { |
| 1681 | while ((att != NULL) && (value != NULL)) { |
| 1682 | if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') && |
| 1683 | (att[3] == 'n') && (att[4] == 's')) |
| 1684 | xmlSAX2AttributeInternal(ctxt, att, value, prefix); |
| 1685 | |
| 1686 | att = atts[i++]; |
| 1687 | value = atts[i++]; |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | /* |
| 1693 | * Search the namespace, note that since the attributes have been |
| 1694 | * processed, the local namespaces are available. |
| 1695 | */ |
| 1696 | ns = xmlSearchNs(ctxt->myDoc, ret, prefix); |
| 1697 | if ((ns == NULL) && (parent != NULL)) |
| 1698 | ns = xmlSearchNs(ctxt->myDoc, parent, prefix); |
| 1699 | if ((prefix != NULL) && (ns == NULL)) { |
| 1700 | ns = xmlNewNs(ret, NULL, prefix); |
Daniel Veillard | 77aad34 | 2006-07-13 06:21:09 +0000 | [diff] [blame] | 1701 | xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
| 1702 | "Namespace prefix %s is not defined\n", |
| 1703 | prefix, NULL); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /* |
| 1707 | * set the namespace node, making sure that if the default namspace |
| 1708 | * is unbound on a parent we simply kee it NULL |
| 1709 | */ |
| 1710 | if ((ns != NULL) && (ns->href != NULL) && |
| 1711 | ((ns->href[0] != 0) || (ns->prefix != NULL))) |
| 1712 | xmlSetNs(ret, ns); |
| 1713 | |
| 1714 | /* |
| 1715 | * process all the other attributes |
| 1716 | */ |
| 1717 | if (atts != NULL) { |
| 1718 | i = 0; |
| 1719 | att = atts[i++]; |
| 1720 | value = atts[i++]; |
| 1721 | if (ctxt->html) { |
| 1722 | while (att != NULL) { |
| 1723 | xmlSAX2AttributeInternal(ctxt, att, value, NULL); |
| 1724 | att = atts[i++]; |
| 1725 | value = atts[i++]; |
| 1726 | } |
| 1727 | } else { |
| 1728 | while ((att != NULL) && (value != NULL)) { |
| 1729 | if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l') || |
| 1730 | (att[3] != 'n') || (att[4] != 's')) |
| 1731 | xmlSAX2AttributeInternal(ctxt, att, value, NULL); |
| 1732 | |
| 1733 | /* |
| 1734 | * Next ones |
| 1735 | */ |
| 1736 | att = atts[i++]; |
| 1737 | value = atts[i++]; |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1742 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1743 | /* |
| 1744 | * If it's the Document root, finish the DTD validation and |
| 1745 | * check the document root element for validity |
| 1746 | */ |
Daniel Veillard | eff45a9 | 2004-10-29 12:10:55 +0000 | [diff] [blame] | 1747 | if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) { |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1748 | int chk; |
| 1749 | |
| 1750 | chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); |
| 1751 | if (chk <= 0) |
| 1752 | ctxt->valid = 0; |
| 1753 | if (chk < 0) |
| 1754 | ctxt->wellFormed = 0; |
| 1755 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); |
Daniel Veillard | eff45a9 | 2004-10-29 12:10:55 +0000 | [diff] [blame] | 1756 | ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1757 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1758 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1759 | |
| 1760 | if (prefix != NULL) |
| 1761 | xmlFree(prefix); |
| 1762 | |
| 1763 | } |
| 1764 | |
| 1765 | /** |
| 1766 | * xmlSAX2EndElement: |
| 1767 | * @ctx: the user data (XML parser context) |
| 1768 | * @name: The element name |
| 1769 | * |
| 1770 | * called when the end of an element has been detected. |
| 1771 | */ |
| 1772 | void |
| 1773 | xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED) |
| 1774 | { |
| 1775 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1776 | xmlNodePtr cur; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1777 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 1778 | if (ctx == NULL) return; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1779 | cur = ctxt->node; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1780 | #ifdef DEBUG_SAX |
| 1781 | if (name == NULL) |
| 1782 | xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(NULL)\n"); |
| 1783 | else |
| 1784 | xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(%s)\n", name); |
| 1785 | #endif |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1786 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1787 | /* Capture end position and add node */ |
| 1788 | if (cur != NULL && ctxt->record_info) { |
Pavel Andrejs | 8ad4da5 | 2012-05-08 11:01:12 +0800 | [diff] [blame] | 1789 | ctxt->nodeInfo->end_pos = ctxt->input->cur - ctxt->input->base; |
| 1790 | ctxt->nodeInfo->end_line = ctxt->input->line; |
| 1791 | ctxt->nodeInfo->node = cur; |
| 1792 | xmlParserAddNodeInfo(ctxt, ctxt->nodeInfo); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1793 | } |
| 1794 | ctxt->nodemem = -1; |
| 1795 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1796 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1797 | if (ctxt->validate && ctxt->wellFormed && |
| 1798 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 1799 | ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, |
| 1800 | cur); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1801 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1802 | |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1803 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1804 | /* |
| 1805 | * end of parsing of this node. |
| 1806 | */ |
| 1807 | #ifdef DEBUG_SAX_TREE |
| 1808 | xmlGenericError(xmlGenericErrorContext, "popping(%s)\n", cur->name); |
| 1809 | #endif |
| 1810 | nodePop(ctxt); |
| 1811 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1812 | #endif /* LIBXML_SAX1_ENABLED || LIBXML_HTML_ENABLE */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 1813 | |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1814 | /* |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1815 | * xmlSAX2TextNode: |
| 1816 | * @ctxt: the parser context |
| 1817 | * @str: the input string |
| 1818 | * @len: the string length |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1819 | * |
Daniel Veillard | 968a03a | 2012-08-13 12:41:33 +0800 | [diff] [blame] | 1820 | * Callback for a text node |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1821 | * |
| 1822 | * Returns the newly allocated string or NULL if not needed or error |
| 1823 | */ |
| 1824 | static xmlNodePtr |
| 1825 | xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { |
| 1826 | xmlNodePtr ret; |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1827 | const xmlChar *intern = NULL; |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1828 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1829 | /* |
| 1830 | * Allocate |
| 1831 | */ |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1832 | if (ctxt->freeElems != NULL) { |
| 1833 | ret = ctxt->freeElems; |
| 1834 | ctxt->freeElems = ret->next; |
| 1835 | ctxt->freeElemsNr--; |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1836 | } else { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1837 | ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1838 | } |
| 1839 | if (ret == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1840 | xmlErrMemory(ctxt, "xmlSAX2Characters"); |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1841 | return(NULL); |
| 1842 | } |
Daniel Veillard | 8874b94 | 2005-08-25 13:19:21 +0000 | [diff] [blame] | 1843 | memset(ret, 0, sizeof(xmlNode)); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1844 | /* |
| 1845 | * intern the formatting blanks found between tags, or the |
| 1846 | * very short strings |
| 1847 | */ |
| 1848 | if (ctxt->dictNames) { |
| 1849 | xmlChar cur = str[len]; |
| 1850 | |
Daniel Veillard | 8874b94 | 2005-08-25 13:19:21 +0000 | [diff] [blame] | 1851 | if ((len < (int) (2 * sizeof(void *))) && |
| 1852 | (ctxt->options & XML_PARSE_COMPACT)) { |
Daniel Veillard | 968a03a | 2012-08-13 12:41:33 +0800 | [diff] [blame] | 1853 | /* store the string in the node overriding properties and nsDef */ |
Daniel Veillard | 8874b94 | 2005-08-25 13:19:21 +0000 | [diff] [blame] | 1854 | xmlChar *tmp = (xmlChar *) &(ret->properties); |
| 1855 | memcpy(tmp, str, len); |
| 1856 | tmp[len] = 0; |
| 1857 | intern = tmp; |
| 1858 | } else if ((len <= 3) && ((cur == '"') || (cur == '\'') || |
Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 1859 | ((cur == '<') && (str[len + 1] != '!')))) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1860 | intern = xmlDictLookup(ctxt->dict, str, len); |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1861 | } else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') && |
Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 1862 | (str[len + 1] != '!')) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1863 | int i; |
| 1864 | |
| 1865 | for (i = 1;i < len;i++) { |
Daniel Veillard | 1a9b708 | 2004-01-02 10:42:01 +0000 | [diff] [blame] | 1866 | if (!IS_BLANK_CH(str[i])) goto skip; |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1867 | } |
| 1868 | intern = xmlDictLookup(ctxt->dict, str, len); |
| 1869 | } |
| 1870 | } |
| 1871 | skip: |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1872 | ret->type = XML_TEXT_NODE; |
| 1873 | |
| 1874 | ret->name = xmlStringText; |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 1875 | if (intern == NULL) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1876 | ret->content = xmlStrndup(str, len); |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 1877 | if (ret->content == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 1878 | xmlSAX2ErrMemory(ctxt, "xmlSAX2TextNode"); |
| 1879 | xmlFree(ret); |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 1880 | return(NULL); |
| 1881 | } |
| 1882 | } else |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1883 | ret->content = (xmlChar *) intern; |
| 1884 | |
Daniel Veillard | 968a03a | 2012-08-13 12:41:33 +0800 | [diff] [blame] | 1885 | if (ctxt->linenumbers) { |
| 1886 | if (ctxt->input != NULL) { |
| 1887 | if (ctxt->input->line < 65535) |
| 1888 | ret->line = (short) ctxt->input->line; |
| 1889 | else { |
| 1890 | ret->line = 65535; |
| 1891 | if (ctxt->options & XML_PARSE_BIG_LINES) |
Daniel Veillard | 7651606 | 2012-09-11 14:02:08 +0800 | [diff] [blame] | 1892 | ret->psvi = (void *) (long) ctxt->input->line; |
Daniel Veillard | 968a03a | 2012-08-13 12:41:33 +0800 | [diff] [blame] | 1893 | } |
| 1894 | } |
| 1895 | } |
Daniel Veillard | 45efd08 | 2008-07-07 13:52:52 +0000 | [diff] [blame] | 1896 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1897 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| 1898 | xmlRegisterNodeDefaultValue(ret); |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1899 | return(ret); |
| 1900 | } |
| 1901 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1902 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1903 | /* |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1904 | * xmlSAX2DecodeAttrEntities: |
| 1905 | * @ctxt: the parser context |
| 1906 | * @str: the input string |
| 1907 | * @len: the string length |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1908 | * |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1909 | * Remove the entities from an attribute value |
| 1910 | * |
| 1911 | * Returns the newly allocated string or NULL if not needed or error |
| 1912 | */ |
| 1913 | static xmlChar * |
| 1914 | xmlSAX2DecodeAttrEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, |
| 1915 | const xmlChar *end) { |
| 1916 | const xmlChar *in; |
| 1917 | xmlChar *ret; |
| 1918 | |
| 1919 | in = str; |
| 1920 | while (in < end) |
| 1921 | if (*in++ == '&') |
| 1922 | goto decode; |
| 1923 | return(NULL); |
| 1924 | decode: |
| 1925 | ctxt->depth++; |
| 1926 | ret = xmlStringLenDecodeEntities(ctxt, str, end - str, |
| 1927 | XML_SUBSTITUTE_REF, 0,0,0); |
| 1928 | ctxt->depth--; |
| 1929 | return(ret); |
| 1930 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1931 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1932 | |
| 1933 | /** |
| 1934 | * xmlSAX2AttributeNs: |
| 1935 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 1936 | * @localname: the local name of the attribute |
| 1937 | * @prefix: the attribute namespace prefix if available |
| 1938 | * @URI: the attribute namespace name if available |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1939 | * @value: Start of the attribute value |
| 1940 | * @valueend: end of the attribute value |
| 1941 | * |
| 1942 | * Handle an attribute that has been read by the parser. |
| 1943 | * The default handling is to convert the attribute into an |
| 1944 | * DOM subtree and past it in a new xmlAttr element added to |
| 1945 | * the element. |
| 1946 | */ |
| 1947 | static void |
| 1948 | xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, |
| 1949 | const xmlChar * localname, |
| 1950 | const xmlChar * prefix, |
| 1951 | const xmlChar * value, |
| 1952 | const xmlChar * valueend) |
| 1953 | { |
| 1954 | xmlAttrPtr ret; |
| 1955 | xmlNsPtr namespace = NULL; |
| 1956 | xmlChar *dup = NULL; |
| 1957 | |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1958 | /* |
| 1959 | * Note: if prefix == NULL, the attribute is not in the default namespace |
| 1960 | */ |
| 1961 | if (prefix != NULL) |
| 1962 | namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, prefix); |
| 1963 | |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 1964 | /* |
| 1965 | * allocate the node |
| 1966 | */ |
| 1967 | if (ctxt->freeAttrs != NULL) { |
| 1968 | ret = ctxt->freeAttrs; |
| 1969 | ctxt->freeAttrs = ret->next; |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 1970 | ctxt->freeAttrsNr--; |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 1971 | memset(ret, 0, sizeof(xmlAttr)); |
| 1972 | ret->type = XML_ATTRIBUTE_NODE; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1973 | |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1974 | ret->parent = ctxt->node; |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 1975 | ret->doc = ctxt->myDoc; |
| 1976 | ret->ns = namespace; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1977 | |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 1978 | if (ctxt->dictNames) |
| 1979 | ret->name = localname; |
| 1980 | else |
| 1981 | ret->name = xmlStrdup(localname); |
| 1982 | |
Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1983 | /* link at the end to preserv order, TODO speed up with a last */ |
| 1984 | if (ctxt->node->properties == NULL) { |
| 1985 | ctxt->node->properties = ret; |
| 1986 | } else { |
| 1987 | xmlAttrPtr prev = ctxt->node->properties; |
| 1988 | |
| 1989 | while (prev->next != NULL) prev = prev->next; |
| 1990 | prev->next = ret; |
| 1991 | ret->prev = prev; |
| 1992 | } |
| 1993 | |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 1994 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| 1995 | xmlRegisterNodeDefaultValue((xmlNodePtr)ret); |
| 1996 | } else { |
| 1997 | if (ctxt->dictNames) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1998 | ret = xmlNewNsPropEatName(ctxt->node, namespace, |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 1999 | (xmlChar *) localname, NULL); |
| 2000 | else |
| 2001 | ret = xmlNewNsProp(ctxt->node, namespace, localname, NULL); |
| 2002 | if (ret == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 2003 | xmlErrMemory(ctxt, "xmlSAX2AttributeNs"); |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2004 | return; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2005 | } |
| 2006 | } |
| 2007 | |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2008 | if ((ctxt->replaceEntities == 0) && (!ctxt->html)) { |
| 2009 | xmlNodePtr tmp; |
| 2010 | |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2011 | /* |
| 2012 | * We know that if there is an entity reference, then |
| 2013 | * the string has been dup'ed and terminates with 0 |
| 2014 | * otherwise with ' or " |
| 2015 | */ |
| 2016 | if (*valueend != 0) { |
| 2017 | tmp = xmlSAX2TextNode(ctxt, value, valueend - value); |
| 2018 | ret->children = tmp; |
| 2019 | ret->last = tmp; |
| 2020 | if (tmp != NULL) { |
| 2021 | tmp->doc = ret->doc; |
| 2022 | tmp->parent = (xmlNodePtr) ret; |
| 2023 | } |
| 2024 | } else { |
| 2025 | ret->children = xmlStringLenGetNodeList(ctxt->myDoc, value, |
| 2026 | valueend - value); |
| 2027 | tmp = ret->children; |
| 2028 | while (tmp != NULL) { |
Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 2029 | tmp->doc = ret->doc; |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2030 | tmp->parent = (xmlNodePtr) ret; |
| 2031 | if (tmp->next == NULL) |
| 2032 | ret->last = tmp; |
| 2033 | tmp = tmp->next; |
| 2034 | } |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2035 | } |
| 2036 | } else if (value != NULL) { |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2037 | xmlNodePtr tmp; |
| 2038 | |
| 2039 | tmp = xmlSAX2TextNode(ctxt, value, valueend - value); |
| 2040 | ret->children = tmp; |
| 2041 | ret->last = tmp; |
| 2042 | if (tmp != NULL) { |
| 2043 | tmp->doc = ret->doc; |
| 2044 | tmp->parent = (xmlNodePtr) ret; |
| 2045 | } |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2048 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2049 | if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && |
| 2050 | ctxt->myDoc && ctxt->myDoc->intSubset) { |
| 2051 | /* |
| 2052 | * If we don't substitute entities, the validation should be |
| 2053 | * done on a value with replaced entities anyway. |
| 2054 | */ |
| 2055 | if (!ctxt->replaceEntities) { |
| 2056 | dup = xmlSAX2DecodeAttrEntities(ctxt, value, valueend); |
| 2057 | if (dup == NULL) { |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2058 | if (*valueend == 0) { |
| 2059 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 2060 | ctxt->myDoc, ctxt->node, ret, value); |
| 2061 | } else { |
| 2062 | /* |
| 2063 | * That should already be normalized. |
| 2064 | * cheaper to finally allocate here than duplicate |
| 2065 | * entry points in the full validation code |
| 2066 | */ |
| 2067 | dup = xmlStrndup(value, valueend - value); |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2068 | |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2069 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 2070 | ctxt->myDoc, ctxt->node, ret, dup); |
| 2071 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2072 | } else { |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2073 | /* |
| 2074 | * dup now contains a string of the flattened attribute |
| 2075 | * content with entities substitued. Check if we need to |
| 2076 | * apply an extra layer of normalization. |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2077 | * It need to be done twice ... it's an extra burden related |
| 2078 | * to the ability to keep references in attributes |
| 2079 | */ |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2080 | if (ctxt->attsSpecial != NULL) { |
| 2081 | xmlChar *nvalnorm; |
| 2082 | xmlChar fn[50]; |
| 2083 | xmlChar *fullname; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2084 | |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2085 | fullname = xmlBuildQName(localname, prefix, fn, 50); |
| 2086 | if (fullname != NULL) { |
| 2087 | ctxt->vctxt.valid = 1; |
| 2088 | nvalnorm = xmlValidCtxtNormalizeAttributeValue( |
| 2089 | &ctxt->vctxt, ctxt->myDoc, |
| 2090 | ctxt->node, fullname, dup); |
| 2091 | if (ctxt->vctxt.valid != 1) |
| 2092 | ctxt->valid = 0; |
| 2093 | |
| 2094 | if ((fullname != fn) && (fullname != localname)) |
| 2095 | xmlFree(fullname); |
| 2096 | if (nvalnorm != NULL) { |
| 2097 | xmlFree(dup); |
| 2098 | dup = nvalnorm; |
| 2099 | } |
| 2100 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2101 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2102 | |
| 2103 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 2104 | ctxt->myDoc, ctxt->node, ret, dup); |
| 2105 | } |
| 2106 | } else { |
Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2107 | /* |
| 2108 | * if entities already have been substitued, then |
| 2109 | * the attribute as passed is already normalized |
| 2110 | */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2111 | dup = xmlStrndup(value, valueend - value); |
| 2112 | |
| 2113 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 2114 | ctxt->myDoc, ctxt->node, ret, dup); |
| 2115 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2116 | } else |
| 2117 | #endif /* LIBXML_VALID_ENABLED */ |
| 2118 | if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) && |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2119 | (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) || |
| 2120 | ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) { |
| 2121 | /* |
| 2122 | * when validating, the ID registration is done at the attribute |
| 2123 | * validation level. Otherwise we have to do specific handling here. |
| 2124 | */ |
Daniel Veillard | 54f9a4f | 2005-09-03 13:28:24 +0000 | [diff] [blame] | 2125 | if ((prefix == ctxt->str_xml) && |
Daniel Veillard | 67f8b1c | 2004-04-09 21:51:49 +0000 | [diff] [blame] | 2126 | (localname[0] == 'i') && (localname[1] == 'd') && |
| 2127 | (localname[2] == 0)) { |
| 2128 | /* |
| 2129 | * Add the xml:id value |
| 2130 | * |
| 2131 | * Open issue: normalization of the value. |
| 2132 | */ |
| 2133 | if (dup == NULL) |
| 2134 | dup = xmlStrndup(value, valueend - value); |
William M. Brack | 5ef2f81 | 2004-05-23 23:56:47 +0000 | [diff] [blame] | 2135 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 68cb4b2 | 2004-04-18 20:55:39 +0000 | [diff] [blame] | 2136 | if (xmlValidateNCName(dup, 1) != 0) { |
| 2137 | xmlErrValid(ctxt, XML_DTD_XMLID_VALUE, |
| 2138 | "xml:id : attribute value %s is not an NCName\n", |
| 2139 | (const char *) dup, NULL); |
| 2140 | } |
William M. Brack | 3f14737 | 2004-05-22 01:09:26 +0000 | [diff] [blame] | 2141 | #endif |
Daniel Veillard | 67f8b1c | 2004-04-09 21:51:49 +0000 | [diff] [blame] | 2142 | xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); |
Daniel Veillard | 54f9a4f | 2005-09-03 13:28:24 +0000 | [diff] [blame] | 2143 | } else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) { |
| 2144 | /* might be worth duplicate entry points and not copy */ |
| 2145 | if (dup == NULL) |
| 2146 | dup = xmlStrndup(value, valueend - value); |
| 2147 | xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); |
| 2148 | } else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) { |
| 2149 | if (dup == NULL) |
| 2150 | dup = xmlStrndup(value, valueend - value); |
| 2151 | xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret); |
Daniel Veillard | 67f8b1c | 2004-04-09 21:51:49 +0000 | [diff] [blame] | 2152 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2153 | } |
| 2154 | if (dup != NULL) |
| 2155 | xmlFree(dup); |
| 2156 | } |
| 2157 | |
| 2158 | /** |
| 2159 | * xmlSAX2StartElementNs: |
| 2160 | * @ctx: the user data (XML parser context) |
| 2161 | * @localname: the local name of the element |
| 2162 | * @prefix: the element namespace prefix if available |
| 2163 | * @URI: the element namespace name if available |
| 2164 | * @nb_namespaces: number of namespace definitions on that node |
| 2165 | * @namespaces: pointer to the array of prefix/URI pairs namespace definitions |
| 2166 | * @nb_attributes: the number of attributes on that node |
Daniel Veillard | 7a02cfe | 2003-09-25 12:18:34 +0000 | [diff] [blame] | 2167 | * @nb_defaulted: the number of defaulted attributes. |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2168 | * @attributes: pointer to the array of (localname/prefix/URI/value/end) |
| 2169 | * attribute values. |
| 2170 | * |
| 2171 | * SAX2 callback when an element start has been detected by the parser. |
| 2172 | * It provides the namespace informations for the element, as well as |
| 2173 | * the new namespace declarations on the element. |
| 2174 | */ |
| 2175 | void |
| 2176 | xmlSAX2StartElementNs(void *ctx, |
| 2177 | const xmlChar *localname, |
| 2178 | const xmlChar *prefix, |
| 2179 | const xmlChar *URI, |
| 2180 | int nb_namespaces, |
| 2181 | const xmlChar **namespaces, |
| 2182 | int nb_attributes, |
| 2183 | int nb_defaulted, |
| 2184 | const xmlChar **attributes) |
| 2185 | { |
| 2186 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2187 | xmlNodePtr ret; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2188 | xmlNodePtr parent; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2189 | xmlNsPtr last = NULL, ns; |
| 2190 | const xmlChar *uri, *pref; |
Daniel Veillard | 77b77b1 | 2012-01-26 19:11:02 +0800 | [diff] [blame] | 2191 | xmlChar *lname = NULL; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2192 | int i, j; |
| 2193 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2194 | if (ctx == NULL) return; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2195 | parent = ctxt->node; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2196 | /* |
| 2197 | * First check on validity: |
| 2198 | */ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2199 | if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2200 | ((ctxt->myDoc->intSubset == NULL) || |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2201 | ((ctxt->myDoc->intSubset->notations == NULL) && |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2202 | (ctxt->myDoc->intSubset->elements == NULL) && |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2203 | (ctxt->myDoc->intSubset->attributes == NULL) && |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2204 | (ctxt->myDoc->intSubset->entities == NULL)))) { |
Daniel Veillard | 6c91aa3 | 2012-10-25 15:33:59 +0800 | [diff] [blame] | 2205 | xmlErrValid(ctxt, XML_DTD_NO_DTD, |
Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 2206 | "Validation failed: no DTD found !", NULL, NULL); |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2207 | ctxt->validate = 0; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2210 | /* |
Daniel Veillard | 77b77b1 | 2012-01-26 19:11:02 +0800 | [diff] [blame] | 2211 | * Take care of the rare case of an undefined namespace prefix |
| 2212 | */ |
| 2213 | if ((prefix != NULL) && (URI == NULL)) { |
| 2214 | if (ctxt->dictNames) { |
| 2215 | const xmlChar *fullname; |
| 2216 | |
| 2217 | fullname = xmlDictQLookup(ctxt->dict, prefix, localname); |
| 2218 | if (fullname != NULL) |
| 2219 | localname = fullname; |
| 2220 | } else { |
| 2221 | lname = xmlBuildQName(localname, prefix, NULL, 0); |
| 2222 | } |
| 2223 | } |
| 2224 | /* |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2225 | * allocate the node |
| 2226 | */ |
| 2227 | if (ctxt->freeElems != NULL) { |
| 2228 | ret = ctxt->freeElems; |
| 2229 | ctxt->freeElems = ret->next; |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2230 | ctxt->freeElemsNr--; |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2231 | memset(ret, 0, sizeof(xmlNode)); |
| 2232 | ret->type = XML_ELEMENT_NODE; |
| 2233 | |
| 2234 | if (ctxt->dictNames) |
| 2235 | ret->name = localname; |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 2236 | else { |
Daniel Veillard | 77b77b1 | 2012-01-26 19:11:02 +0800 | [diff] [blame] | 2237 | if (lname == NULL) |
| 2238 | ret->name = xmlStrdup(localname); |
| 2239 | else |
| 2240 | ret->name = lname; |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 2241 | if (ret->name == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 2242 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 2243 | return; |
| 2244 | } |
| 2245 | } |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2246 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| 2247 | xmlRegisterNodeDefaultValue(ret); |
| 2248 | } else { |
| 2249 | if (ctxt->dictNames) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2250 | ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2251 | (xmlChar *) localname, NULL); |
Daniel Veillard | 77b77b1 | 2012-01-26 19:11:02 +0800 | [diff] [blame] | 2252 | else if (lname == NULL) |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2253 | ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL); |
Daniel Veillard | 77b77b1 | 2012-01-26 19:11:02 +0800 | [diff] [blame] | 2254 | else |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2255 | ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, |
Daniel Veillard | 77b77b1 | 2012-01-26 19:11:02 +0800 | [diff] [blame] | 2256 | (xmlChar *) lname, NULL); |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2257 | if (ret == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 2258 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2259 | return; |
| 2260 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2261 | } |
Daniel Veillard | d9e9c9d | 2003-09-18 22:03:46 +0000 | [diff] [blame] | 2262 | if (ctxt->linenumbers) { |
Daniel Veillard | 3e35f8e | 2003-10-21 00:05:38 +0000 | [diff] [blame] | 2263 | if (ctxt->input != NULL) { |
| 2264 | if (ctxt->input->line < 65535) |
| 2265 | ret->line = (short) ctxt->input->line; |
| 2266 | else |
| 2267 | ret->line = 65535; |
| 2268 | } |
Daniel Veillard | d9e9c9d | 2003-09-18 22:03:46 +0000 | [diff] [blame] | 2269 | } |
Daniel Veillard | 8a44e59 | 2003-09-15 14:50:06 +0000 | [diff] [blame] | 2270 | |
Tim Elliott | 71a243d | 2012-01-17 19:25:08 -0800 | [diff] [blame] | 2271 | if (parent == NULL) { |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2272 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2273 | } |
| 2274 | /* |
| 2275 | * Build the namespace list |
| 2276 | */ |
| 2277 | for (i = 0,j = 0;j < nb_namespaces;j++) { |
| 2278 | pref = namespaces[i++]; |
| 2279 | uri = namespaces[i++]; |
| 2280 | ns = xmlNewNs(NULL, uri, pref); |
| 2281 | if (ns != NULL) { |
| 2282 | if (last == NULL) { |
| 2283 | ret->nsDef = last = ns; |
| 2284 | } else { |
| 2285 | last->next = ns; |
| 2286 | last = ns; |
| 2287 | } |
| 2288 | if ((URI != NULL) && (prefix == pref)) |
| 2289 | ret->ns = ns; |
| 2290 | } else { |
Daniel Veillard | aa54d37 | 2010-09-09 18:17:47 +0200 | [diff] [blame] | 2291 | /* |
| 2292 | * any out of memory error would already have been raised |
| 2293 | * but we can't be garanteed it's the actual error due to the |
| 2294 | * API, best is to skip in this case |
| 2295 | */ |
| 2296 | continue; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2297 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2298 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | d9e9c9d | 2003-09-18 22:03:46 +0000 | [diff] [blame] | 2299 | if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && |
| 2300 | ctxt->myDoc && ctxt->myDoc->intSubset) { |
| 2301 | ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc, |
| 2302 | ret, prefix, ns, uri); |
| 2303 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2304 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2305 | } |
| 2306 | ctxt->nodemem = -1; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2307 | |
| 2308 | /* |
| 2309 | * We are parsing a new node. |
| 2310 | */ |
| 2311 | nodePush(ctxt, ret); |
| 2312 | |
| 2313 | /* |
| 2314 | * Link the child element |
| 2315 | */ |
| 2316 | if (parent != NULL) { |
| 2317 | if (parent->type == XML_ELEMENT_NODE) { |
| 2318 | xmlAddChild(parent, ret); |
| 2319 | } else { |
| 2320 | xmlAddSibling(parent, ret); |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | /* |
| 2325 | * Insert the defaulted attributes from the DTD only if requested: |
| 2326 | */ |
| 2327 | if ((nb_defaulted != 0) && |
| 2328 | ((ctxt->loadsubset & XML_COMPLETE_ATTRS) == 0)) |
| 2329 | nb_attributes -= nb_defaulted; |
| 2330 | |
| 2331 | /* |
| 2332 | * Search the namespace if it wasn't already found |
William M. Brack | bf5cf21 | 2004-08-31 06:47:17 +0000 | [diff] [blame] | 2333 | * Note that, if prefix is NULL, this searches for the default Ns |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2334 | */ |
| 2335 | if ((URI != NULL) && (ret->ns == NULL)) { |
William M. Brack | bf5cf21 | 2004-08-31 06:47:17 +0000 | [diff] [blame] | 2336 | ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix); |
Daniel Veillard | 6977c6c | 2006-01-04 14:03:10 +0000 | [diff] [blame] | 2337 | if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { |
| 2338 | ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix); |
| 2339 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2340 | if (ret->ns == NULL) { |
| 2341 | ns = xmlNewNs(ret, NULL, prefix); |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 2342 | if (ns == NULL) { |
Daniel Veillard | 6977c6c | 2006-01-04 14:03:10 +0000 | [diff] [blame] | 2343 | |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 2344 | xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); |
William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 2345 | return; |
| 2346 | } |
Daniel Veillard | 74eaec1 | 2009-08-26 15:57:20 +0200 | [diff] [blame] | 2347 | if (prefix != NULL) |
| 2348 | xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
| 2349 | "Namespace prefix %s was not found\n", |
| 2350 | prefix, NULL); |
| 2351 | else |
| 2352 | xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
| 2353 | "Namespace default prefix was not found\n", |
| 2354 | NULL, NULL); |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | /* |
| 2359 | * process all the other attributes |
| 2360 | */ |
| 2361 | if (nb_attributes > 0) { |
| 2362 | for (j = 0,i = 0;i < nb_attributes;i++,j+=5) { |
Daniel Veillard | 1c98927 | 2012-01-26 19:43:06 +0800 | [diff] [blame] | 2363 | /* |
| 2364 | * Handle the rare case of an undefined atribute prefix |
| 2365 | */ |
| 2366 | if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) { |
| 2367 | if (ctxt->dictNames) { |
| 2368 | const xmlChar *fullname; |
| 2369 | |
| 2370 | fullname = xmlDictQLookup(ctxt->dict, attributes[j+1], |
| 2371 | attributes[j]); |
| 2372 | if (fullname != NULL) { |
| 2373 | xmlSAX2AttributeNs(ctxt, fullname, NULL, |
| 2374 | attributes[j+3], attributes[j+4]); |
| 2375 | continue; |
| 2376 | } |
| 2377 | } else { |
| 2378 | lname = xmlBuildQName(attributes[j], attributes[j+1], |
| 2379 | NULL, 0); |
| 2380 | if (lname != NULL) { |
| 2381 | xmlSAX2AttributeNs(ctxt, lname, NULL, |
| 2382 | attributes[j+3], attributes[j+4]); |
| 2383 | xmlFree(lname); |
| 2384 | continue; |
| 2385 | } |
| 2386 | } |
| 2387 | } |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2388 | xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1], |
Daniel Veillard | 1c98927 | 2012-01-26 19:43:06 +0800 | [diff] [blame] | 2389 | attributes[j+3], attributes[j+4]); |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2393 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2394 | /* |
| 2395 | * If it's the Document root, finish the DTD validation and |
| 2396 | * check the document root element for validity |
| 2397 | */ |
Daniel Veillard | eff45a9 | 2004-10-29 12:10:55 +0000 | [diff] [blame] | 2398 | if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) { |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2399 | int chk; |
| 2400 | |
| 2401 | chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); |
| 2402 | if (chk <= 0) |
| 2403 | ctxt->valid = 0; |
| 2404 | if (chk < 0) |
| 2405 | ctxt->wellFormed = 0; |
| 2406 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); |
Daniel Veillard | eff45a9 | 2004-10-29 12:10:55 +0000 | [diff] [blame] | 2407 | ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2408 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2409 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | /** |
| 2413 | * xmlSAX2EndElementNs: |
| 2414 | * @ctx: the user data (XML parser context) |
| 2415 | * @localname: the local name of the element |
| 2416 | * @prefix: the element namespace prefix if available |
| 2417 | * @URI: the element namespace name if available |
| 2418 | * |
| 2419 | * SAX2 callback when an element end has been detected by the parser. |
| 2420 | * It provides the namespace informations for the element. |
| 2421 | */ |
| 2422 | void |
| 2423 | xmlSAX2EndElementNs(void *ctx, |
| 2424 | const xmlChar * localname ATTRIBUTE_UNUSED, |
| 2425 | const xmlChar * prefix ATTRIBUTE_UNUSED, |
| 2426 | const xmlChar * URI ATTRIBUTE_UNUSED) |
| 2427 | { |
| 2428 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2429 | xmlParserNodeInfo node_info; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2430 | xmlNodePtr cur; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2431 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2432 | if (ctx == NULL) return; |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2433 | cur = ctxt->node; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2434 | /* Capture end position and add node */ |
| 2435 | if ((ctxt->record_info) && (cur != NULL)) { |
| 2436 | node_info.end_pos = ctxt->input->cur - ctxt->input->base; |
| 2437 | node_info.end_line = ctxt->input->line; |
| 2438 | node_info.node = cur; |
| 2439 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 2440 | } |
| 2441 | ctxt->nodemem = -1; |
| 2442 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2443 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2444 | if (ctxt->validate && ctxt->wellFormed && |
| 2445 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 2446 | ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, cur); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2447 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2448 | |
| 2449 | /* |
| 2450 | * end of parsing of this node. |
| 2451 | */ |
| 2452 | nodePop(ctxt); |
| 2453 | } |
| 2454 | |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2455 | /** |
| 2456 | * xmlSAX2Reference: |
| 2457 | * @ctx: the user data (XML parser context) |
| 2458 | * @name: The entity name |
| 2459 | * |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2460 | * called when an entity xmlSAX2Reference is detected. |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2461 | */ |
| 2462 | void |
| 2463 | xmlSAX2Reference(void *ctx, const xmlChar *name) |
| 2464 | { |
| 2465 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2466 | xmlNodePtr ret; |
| 2467 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2468 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2469 | #ifdef DEBUG_SAX |
| 2470 | xmlGenericError(xmlGenericErrorContext, |
| 2471 | "SAX.xmlSAX2Reference(%s)\n", name); |
| 2472 | #endif |
| 2473 | if (name[0] == '#') |
| 2474 | ret = xmlNewCharRef(ctxt->myDoc, name); |
| 2475 | else |
| 2476 | ret = xmlNewReference(ctxt->myDoc, name); |
| 2477 | #ifdef DEBUG_SAX_TREE |
| 2478 | xmlGenericError(xmlGenericErrorContext, |
| 2479 | "add xmlSAX2Reference %s to %s \n", name, ctxt->node->name); |
| 2480 | #endif |
Daniel Veillard | b242b08 | 2008-02-08 09:56:31 +0000 | [diff] [blame] | 2481 | if (xmlAddChild(ctxt->node, ret) == NULL) { |
| 2482 | xmlFreeNode(ret); |
| 2483 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /** |
| 2487 | * xmlSAX2Characters: |
| 2488 | * @ctx: the user data (XML parser context) |
| 2489 | * @ch: a xmlChar string |
| 2490 | * @len: the number of xmlChar |
| 2491 | * |
| 2492 | * receiving some chars from the parser. |
| 2493 | */ |
| 2494 | void |
| 2495 | xmlSAX2Characters(void *ctx, const xmlChar *ch, int len) |
| 2496 | { |
| 2497 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2498 | xmlNodePtr lastChild; |
| 2499 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2500 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2501 | #ifdef DEBUG_SAX |
| 2502 | xmlGenericError(xmlGenericErrorContext, |
| 2503 | "SAX.xmlSAX2Characters(%.30s, %d)\n", ch, len); |
| 2504 | #endif |
| 2505 | /* |
| 2506 | * Handle the data if any. If there is no child |
| 2507 | * add it as content, otherwise if the last child is text, |
| 2508 | * concatenate it, else create a new node of type text. |
| 2509 | */ |
| 2510 | |
| 2511 | if (ctxt->node == NULL) { |
| 2512 | #ifdef DEBUG_SAX_TREE |
| 2513 | xmlGenericError(xmlGenericErrorContext, |
| 2514 | "add chars: ctxt->node == NULL !\n"); |
| 2515 | #endif |
| 2516 | return; |
| 2517 | } |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2518 | lastChild = ctxt->node->last; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2519 | #ifdef DEBUG_SAX_TREE |
| 2520 | xmlGenericError(xmlGenericErrorContext, |
| 2521 | "add chars to %s \n", ctxt->node->name); |
| 2522 | #endif |
| 2523 | |
| 2524 | /* |
| 2525 | * Here we needed an accelerator mechanism in case of very large |
| 2526 | * elements. Use an attribute in the structure !!! |
| 2527 | */ |
| 2528 | if (lastChild == NULL) { |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2529 | lastChild = xmlSAX2TextNode(ctxt, ch, len); |
| 2530 | if (lastChild != NULL) { |
| 2531 | ctxt->node->children = lastChild; |
| 2532 | ctxt->node->last = lastChild; |
| 2533 | lastChild->parent = ctxt->node; |
| 2534 | lastChild->doc = ctxt->node->doc; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2535 | ctxt->nodelen = len; |
| 2536 | ctxt->nodemem = len + 1; |
William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 2537 | } else { |
| 2538 | xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); |
| 2539 | return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2540 | } |
| 2541 | } else { |
| 2542 | int coalesceText = (lastChild != NULL) && |
| 2543 | (lastChild->type == XML_TEXT_NODE) && |
| 2544 | (lastChild->name == xmlStringText); |
| 2545 | if ((coalesceText) && (ctxt->nodemem != 0)) { |
| 2546 | /* |
| 2547 | * The whole point of maintaining nodelen and nodemem, |
| 2548 | * xmlTextConcat is too costly, i.e. compute length, |
| 2549 | * reallocate a new buffer, move data, append ch. Here |
| 2550 | * We try to minimaze realloc() uses and avoid copying |
| 2551 | * and recomputing length over and over. |
| 2552 | */ |
Daniel Veillard | 8874b94 | 2005-08-25 13:19:21 +0000 | [diff] [blame] | 2553 | if (lastChild->content == (xmlChar *)&(lastChild->properties)) { |
| 2554 | lastChild->content = xmlStrdup(lastChild->content); |
| 2555 | lastChild->properties = NULL; |
| 2556 | } else if ((ctxt->nodemem == ctxt->nodelen + 1) && |
| 2557 | (xmlDictOwns(ctxt->dict, lastChild->content))) { |
Daniel Veillard | 2b0f879 | 2003-10-10 19:36:36 +0000 | [diff] [blame] | 2558 | lastChild->content = xmlStrdup(lastChild->content); |
| 2559 | } |
Daniel Veillard | 97ff9b3 | 2009-01-18 21:43:30 +0000 | [diff] [blame] | 2560 | if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGTH) && |
Daniel Veillard | 1fb2e0d | 2009-01-18 14:08:36 +0000 | [diff] [blame] | 2561 | ((ctxt->options & XML_PARSE_HUGE) == 0)) { |
| 2562 | xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node"); |
| 2563 | return; |
| 2564 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 2565 | if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len || |
Daniel Veillard | 1dc9feb | 2008-11-17 15:59:21 +0000 | [diff] [blame] | 2566 | (size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) { |
Daniel Veillard | 1fb2e0d | 2009-01-18 14:08:36 +0000 | [diff] [blame] | 2567 | xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented"); |
| 2568 | return; |
Daniel Veillard | 1dc9feb | 2008-11-17 15:59:21 +0000 | [diff] [blame] | 2569 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2570 | if (ctxt->nodelen + len >= ctxt->nodemem) { |
| 2571 | xmlChar *newbuf; |
Daniel Veillard | 1dc9feb | 2008-11-17 15:59:21 +0000 | [diff] [blame] | 2572 | size_t size; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2573 | |
| 2574 | size = ctxt->nodemem + len; |
| 2575 | size *= 2; |
| 2576 | newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); |
| 2577 | if (newbuf == NULL) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 2578 | xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2579 | return; |
| 2580 | } |
| 2581 | ctxt->nodemem = size; |
| 2582 | lastChild->content = newbuf; |
| 2583 | } |
| 2584 | memcpy(&lastChild->content[ctxt->nodelen], ch, len); |
| 2585 | ctxt->nodelen += len; |
| 2586 | lastChild->content[ctxt->nodelen] = 0; |
| 2587 | } else if (coalesceText) { |
| 2588 | if (xmlTextConcat(lastChild, ch, len)) { |
William M. Brack | 42331a9 | 2004-07-29 07:07:16 +0000 | [diff] [blame] | 2589 | xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2590 | } |
| 2591 | if (ctxt->node->children != NULL) { |
| 2592 | ctxt->nodelen = xmlStrlen(lastChild->content); |
| 2593 | ctxt->nodemem = ctxt->nodelen + 1; |
| 2594 | } |
| 2595 | } else { |
| 2596 | /* Mixed content, first time */ |
Daniel Veillard | 1989505 | 2003-09-17 13:59:32 +0000 | [diff] [blame] | 2597 | lastChild = xmlSAX2TextNode(ctxt, ch, len); |
| 2598 | if (lastChild != NULL) { |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2599 | xmlAddChild(ctxt->node, lastChild); |
| 2600 | if (ctxt->node->children != NULL) { |
| 2601 | ctxt->nodelen = len; |
| 2602 | ctxt->nodemem = len + 1; |
| 2603 | } |
| 2604 | } |
| 2605 | } |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | /** |
| 2610 | * xmlSAX2IgnorableWhitespace: |
| 2611 | * @ctx: the user data (XML parser context) |
| 2612 | * @ch: a xmlChar string |
| 2613 | * @len: the number of xmlChar |
| 2614 | * |
| 2615 | * receiving some ignorable whitespaces from the parser. |
| 2616 | * UNUSED: by default the DOM building will use xmlSAX2Characters |
| 2617 | */ |
| 2618 | void |
| 2619 | xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED) |
| 2620 | { |
| 2621 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
| 2622 | #ifdef DEBUG_SAX |
| 2623 | xmlGenericError(xmlGenericErrorContext, |
| 2624 | "SAX.xmlSAX2IgnorableWhitespace(%.30s, %d)\n", ch, len); |
| 2625 | #endif |
| 2626 | } |
| 2627 | |
| 2628 | /** |
| 2629 | * xmlSAX2ProcessingInstruction: |
| 2630 | * @ctx: the user data (XML parser context) |
| 2631 | * @target: the target name |
| 2632 | * @data: the PI data's |
| 2633 | * |
| 2634 | * A processing instruction has been parsed. |
| 2635 | */ |
| 2636 | void |
| 2637 | xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target, |
| 2638 | const xmlChar *data) |
| 2639 | { |
| 2640 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2641 | xmlNodePtr ret; |
Daniel Veillard | 6128c01 | 2004-11-08 17:16:15 +0000 | [diff] [blame] | 2642 | xmlNodePtr parent; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2643 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2644 | if (ctx == NULL) return; |
Daniel Veillard | 6128c01 | 2004-11-08 17:16:15 +0000 | [diff] [blame] | 2645 | parent = ctxt->node; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2646 | #ifdef DEBUG_SAX |
| 2647 | xmlGenericError(xmlGenericErrorContext, |
| 2648 | "SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target, data); |
| 2649 | #endif |
| 2650 | |
Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 2651 | ret = xmlNewDocPI(ctxt->myDoc, target, data); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2652 | if (ret == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2653 | |
Daniel Veillard | 73da77e | 2005-08-24 14:05:37 +0000 | [diff] [blame] | 2654 | if (ctxt->linenumbers) { |
| 2655 | if (ctxt->input != NULL) { |
| 2656 | if (ctxt->input->line < 65535) |
| 2657 | ret->line = (short) ctxt->input->line; |
| 2658 | else |
| 2659 | ret->line = 65535; |
| 2660 | } |
| 2661 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2662 | if (ctxt->inSubset == 1) { |
| 2663 | xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret); |
| 2664 | return; |
| 2665 | } else if (ctxt->inSubset == 2) { |
| 2666 | xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret); |
| 2667 | return; |
| 2668 | } |
Tim Elliott | 71a243d | 2012-01-17 19:25:08 -0800 | [diff] [blame] | 2669 | if (parent == NULL) { |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2670 | #ifdef DEBUG_SAX_TREE |
| 2671 | xmlGenericError(xmlGenericErrorContext, |
| 2672 | "Setting PI %s as root\n", target); |
| 2673 | #endif |
| 2674 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
| 2675 | return; |
| 2676 | } |
| 2677 | if (parent->type == XML_ELEMENT_NODE) { |
| 2678 | #ifdef DEBUG_SAX_TREE |
| 2679 | xmlGenericError(xmlGenericErrorContext, |
| 2680 | "adding PI %s child to %s\n", target, parent->name); |
| 2681 | #endif |
| 2682 | xmlAddChild(parent, ret); |
| 2683 | } else { |
| 2684 | #ifdef DEBUG_SAX_TREE |
| 2685 | xmlGenericError(xmlGenericErrorContext, |
| 2686 | "adding PI %s sibling to ", target); |
| 2687 | xmlDebugDumpOneNode(stderr, parent, 0); |
| 2688 | #endif |
| 2689 | xmlAddSibling(parent, ret); |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | /** |
| 2694 | * xmlSAX2Comment: |
| 2695 | * @ctx: the user data (XML parser context) |
| 2696 | * @value: the xmlSAX2Comment content |
| 2697 | * |
| 2698 | * A xmlSAX2Comment has been parsed. |
| 2699 | */ |
| 2700 | void |
| 2701 | xmlSAX2Comment(void *ctx, const xmlChar *value) |
| 2702 | { |
| 2703 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2704 | xmlNodePtr ret; |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2705 | xmlNodePtr parent; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2706 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2707 | if (ctx == NULL) return; |
| 2708 | parent = ctxt->node; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2709 | #ifdef DEBUG_SAX |
| 2710 | xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2Comment(%s)\n", value); |
| 2711 | #endif |
| 2712 | ret = xmlNewDocComment(ctxt->myDoc, value); |
| 2713 | if (ret == NULL) return; |
Daniel Veillard | 73da77e | 2005-08-24 14:05:37 +0000 | [diff] [blame] | 2714 | if (ctxt->linenumbers) { |
| 2715 | if (ctxt->input != NULL) { |
| 2716 | if (ctxt->input->line < 65535) |
| 2717 | ret->line = (short) ctxt->input->line; |
| 2718 | else |
| 2719 | ret->line = 65535; |
| 2720 | } |
| 2721 | } |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2722 | |
| 2723 | if (ctxt->inSubset == 1) { |
| 2724 | xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret); |
| 2725 | return; |
| 2726 | } else if (ctxt->inSubset == 2) { |
| 2727 | xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret); |
| 2728 | return; |
| 2729 | } |
Tim Elliott | 71a243d | 2012-01-17 19:25:08 -0800 | [diff] [blame] | 2730 | if (parent == NULL) { |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2731 | #ifdef DEBUG_SAX_TREE |
| 2732 | xmlGenericError(xmlGenericErrorContext, |
| 2733 | "Setting xmlSAX2Comment as root\n"); |
| 2734 | #endif |
| 2735 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
| 2736 | return; |
| 2737 | } |
| 2738 | if (parent->type == XML_ELEMENT_NODE) { |
| 2739 | #ifdef DEBUG_SAX_TREE |
| 2740 | xmlGenericError(xmlGenericErrorContext, |
| 2741 | "adding xmlSAX2Comment child to %s\n", parent->name); |
| 2742 | #endif |
| 2743 | xmlAddChild(parent, ret); |
| 2744 | } else { |
| 2745 | #ifdef DEBUG_SAX_TREE |
| 2746 | xmlGenericError(xmlGenericErrorContext, |
| 2747 | "adding xmlSAX2Comment sibling to "); |
| 2748 | xmlDebugDumpOneNode(stderr, parent, 0); |
| 2749 | #endif |
| 2750 | xmlAddSibling(parent, ret); |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | /** |
| 2755 | * xmlSAX2CDataBlock: |
| 2756 | * @ctx: the user data (XML parser context) |
| 2757 | * @value: The pcdata content |
| 2758 | * @len: the block length |
| 2759 | * |
| 2760 | * called when a pcdata block has been parsed |
| 2761 | */ |
| 2762 | void |
| 2763 | xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len) |
| 2764 | { |
| 2765 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 2766 | xmlNodePtr ret, lastChild; |
| 2767 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 2768 | if (ctx == NULL) return; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2769 | #ifdef DEBUG_SAX |
| 2770 | xmlGenericError(xmlGenericErrorContext, |
| 2771 | "SAX.pcdata(%.10s, %d)\n", value, len); |
| 2772 | #endif |
| 2773 | lastChild = xmlGetLastChild(ctxt->node); |
| 2774 | #ifdef DEBUG_SAX_TREE |
| 2775 | xmlGenericError(xmlGenericErrorContext, |
| 2776 | "add chars to %s \n", ctxt->node->name); |
| 2777 | #endif |
| 2778 | if ((lastChild != NULL) && |
| 2779 | (lastChild->type == XML_CDATA_SECTION_NODE)) { |
| 2780 | xmlTextConcat(lastChild, value, len); |
| 2781 | } else { |
| 2782 | ret = xmlNewCDataBlock(ctxt->myDoc, value, len); |
| 2783 | xmlAddChild(ctxt->node, ret); |
| 2784 | } |
| 2785 | } |
| 2786 | |
Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2787 | static int xmlSAX2DefaultVersionValue = 2; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2788 | |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2789 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2790 | /** |
| 2791 | * xmlSAXDefaultVersion: |
| 2792 | * @version: the version, 1 or 2 |
| 2793 | * |
| 2794 | * Set the default version of SAX used globally by the library. |
William M. Brack | 96d2eff | 2004-06-30 11:48:47 +0000 | [diff] [blame] | 2795 | * By default, during initialization the default is set to 2. |
| 2796 | * Note that it is generally a better coding style to use |
| 2797 | * xmlSAXVersion() to set up the version explicitly for a given |
| 2798 | * parsing context. |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2799 | * |
| 2800 | * Returns the previous value in case of success and -1 in case of error. |
| 2801 | */ |
| 2802 | int |
| 2803 | xmlSAXDefaultVersion(int version) |
| 2804 | { |
| 2805 | int ret = xmlSAX2DefaultVersionValue; |
| 2806 | |
| 2807 | if ((version != 1) && (version != 2)) |
| 2808 | return(-1); |
| 2809 | xmlSAX2DefaultVersionValue = version; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2810 | return(ret); |
| 2811 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2812 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2813 | |
| 2814 | /** |
| 2815 | * xmlSAXVersion: |
| 2816 | * @hdlr: the SAX handler |
| 2817 | * @version: the version, 1 or 2 |
| 2818 | * |
| 2819 | * Initialize the default XML SAX handler according to the version |
| 2820 | * |
| 2821 | * Returns 0 in case of success and -1 in case of error. |
| 2822 | */ |
| 2823 | int |
| 2824 | xmlSAXVersion(xmlSAXHandler *hdlr, int version) |
| 2825 | { |
| 2826 | if (hdlr == NULL) return(-1); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2827 | if (version == 2) { |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2828 | hdlr->startElement = NULL; |
| 2829 | hdlr->endElement = NULL; |
| 2830 | hdlr->startElementNs = xmlSAX2StartElementNs; |
| 2831 | hdlr->endElementNs = xmlSAX2EndElementNs; |
Daniel Veillard | ffbbed4 | 2003-10-10 14:46:54 +0000 | [diff] [blame] | 2832 | hdlr->serror = NULL; |
Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 2833 | hdlr->initialized = XML_SAX2_MAGIC; |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2834 | #ifdef LIBXML_SAX1_ENABLED |
| 2835 | } else if (version == 1) { |
| 2836 | hdlr->startElement = xmlSAX2StartElement; |
| 2837 | hdlr->endElement = xmlSAX2EndElement; |
| 2838 | hdlr->initialized = 1; |
| 2839 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2840 | } else |
| 2841 | return(-1); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2842 | hdlr->internalSubset = xmlSAX2InternalSubset; |
| 2843 | hdlr->externalSubset = xmlSAX2ExternalSubset; |
| 2844 | hdlr->isStandalone = xmlSAX2IsStandalone; |
| 2845 | hdlr->hasInternalSubset = xmlSAX2HasInternalSubset; |
| 2846 | hdlr->hasExternalSubset = xmlSAX2HasExternalSubset; |
| 2847 | hdlr->resolveEntity = xmlSAX2ResolveEntity; |
| 2848 | hdlr->getEntity = xmlSAX2GetEntity; |
| 2849 | hdlr->getParameterEntity = xmlSAX2GetParameterEntity; |
| 2850 | hdlr->entityDecl = xmlSAX2EntityDecl; |
| 2851 | hdlr->attributeDecl = xmlSAX2AttributeDecl; |
| 2852 | hdlr->elementDecl = xmlSAX2ElementDecl; |
| 2853 | hdlr->notationDecl = xmlSAX2NotationDecl; |
| 2854 | hdlr->unparsedEntityDecl = xmlSAX2UnparsedEntityDecl; |
| 2855 | hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator; |
| 2856 | hdlr->startDocument = xmlSAX2StartDocument; |
| 2857 | hdlr->endDocument = xmlSAX2EndDocument; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2858 | hdlr->reference = xmlSAX2Reference; |
| 2859 | hdlr->characters = xmlSAX2Characters; |
| 2860 | hdlr->cdataBlock = xmlSAX2CDataBlock; |
| 2861 | hdlr->ignorableWhitespace = xmlSAX2Characters; |
| 2862 | hdlr->processingInstruction = xmlSAX2ProcessingInstruction; |
| 2863 | hdlr->comment = xmlSAX2Comment; |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2864 | hdlr->warning = xmlParserWarning; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2865 | hdlr->error = xmlParserError; |
| 2866 | hdlr->fatalError = xmlParserError; |
| 2867 | |
Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2868 | return(0); |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * xmlSAX2InitDefaultSAXHandler: |
| 2873 | * @hdlr: the SAX handler |
| 2874 | * @warning: flag if non-zero sets the handler warning procedure |
| 2875 | * |
| 2876 | * Initialize the default XML SAX2 handler |
| 2877 | */ |
| 2878 | void |
| 2879 | xmlSAX2InitDefaultSAXHandler(xmlSAXHandler *hdlr, int warning) |
| 2880 | { |
| 2881 | if ((hdlr == NULL) || (hdlr->initialized != 0)) |
| 2882 | return; |
| 2883 | |
| 2884 | xmlSAXVersion(hdlr, xmlSAX2DefaultVersionValue); |
| 2885 | if (warning == 0) |
| 2886 | hdlr->warning = NULL; |
| 2887 | else |
| 2888 | hdlr->warning = xmlParserWarning; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | /** |
| 2892 | * xmlDefaultSAXHandlerInit: |
| 2893 | * |
| 2894 | * Initialize the default SAX2 handler |
| 2895 | */ |
| 2896 | void |
| 2897 | xmlDefaultSAXHandlerInit(void) |
| 2898 | { |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2899 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 2900 | xmlSAXVersion((xmlSAXHandlerPtr) &xmlDefaultSAXHandler, 1); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2901 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | #ifdef LIBXML_HTML_ENABLED |
| 2905 | |
| 2906 | /** |
| 2907 | * xmlSAX2InitHtmlDefaultSAXHandler: |
| 2908 | * @hdlr: the SAX handler |
| 2909 | * |
| 2910 | * Initialize the default HTML SAX2 handler |
| 2911 | */ |
| 2912 | void |
| 2913 | xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr) |
| 2914 | { |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2915 | if ((hdlr == NULL) || (hdlr->initialized != 0)) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2916 | return; |
| 2917 | |
| 2918 | hdlr->internalSubset = xmlSAX2InternalSubset; |
| 2919 | hdlr->externalSubset = NULL; |
| 2920 | hdlr->isStandalone = NULL; |
| 2921 | hdlr->hasInternalSubset = NULL; |
| 2922 | hdlr->hasExternalSubset = NULL; |
| 2923 | hdlr->resolveEntity = NULL; |
| 2924 | hdlr->getEntity = xmlSAX2GetEntity; |
| 2925 | hdlr->getParameterEntity = NULL; |
| 2926 | hdlr->entityDecl = NULL; |
| 2927 | hdlr->attributeDecl = NULL; |
| 2928 | hdlr->elementDecl = NULL; |
| 2929 | hdlr->notationDecl = NULL; |
| 2930 | hdlr->unparsedEntityDecl = NULL; |
| 2931 | hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator; |
| 2932 | hdlr->startDocument = xmlSAX2StartDocument; |
| 2933 | hdlr->endDocument = xmlSAX2EndDocument; |
| 2934 | hdlr->startElement = xmlSAX2StartElement; |
| 2935 | hdlr->endElement = xmlSAX2EndElement; |
| 2936 | hdlr->reference = NULL; |
| 2937 | hdlr->characters = xmlSAX2Characters; |
| 2938 | hdlr->cdataBlock = xmlSAX2CDataBlock; |
| 2939 | hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace; |
Daniel Veillard | fc484dd | 2004-10-22 14:34:23 +0000 | [diff] [blame] | 2940 | hdlr->processingInstruction = xmlSAX2ProcessingInstruction; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2941 | hdlr->comment = xmlSAX2Comment; |
| 2942 | hdlr->warning = xmlParserWarning; |
| 2943 | hdlr->error = xmlParserError; |
| 2944 | hdlr->fatalError = xmlParserError; |
| 2945 | |
Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 2946 | hdlr->initialized = 1; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | /** |
| 2950 | * htmlDefaultSAXHandlerInit: |
| 2951 | * |
| 2952 | * Initialize the default SAX handler |
| 2953 | */ |
| 2954 | void |
| 2955 | htmlDefaultSAXHandlerInit(void) |
| 2956 | { |
Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 2957 | xmlSAX2InitHtmlDefaultSAXHandler((xmlSAXHandlerPtr) &htmlDefaultSAXHandler); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | #endif /* LIBXML_HTML_ENABLED */ |
| 2961 | |
| 2962 | #ifdef LIBXML_DOCB_ENABLED |
| 2963 | |
| 2964 | /** |
| 2965 | * xmlSAX2InitDocbDefaultSAXHandler: |
| 2966 | * @hdlr: the SAX handler |
| 2967 | * |
| 2968 | * Initialize the default DocBook SAX2 handler |
| 2969 | */ |
| 2970 | void |
| 2971 | xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler *hdlr) |
| 2972 | { |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2973 | if ((hdlr == NULL) || (hdlr->initialized != 0)) |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 2974 | return; |
| 2975 | |
| 2976 | hdlr->internalSubset = xmlSAX2InternalSubset; |
| 2977 | hdlr->externalSubset = NULL; |
| 2978 | hdlr->isStandalone = xmlSAX2IsStandalone; |
| 2979 | hdlr->hasInternalSubset = xmlSAX2HasInternalSubset; |
| 2980 | hdlr->hasExternalSubset = xmlSAX2HasExternalSubset; |
| 2981 | hdlr->resolveEntity = xmlSAX2ResolveEntity; |
| 2982 | hdlr->getEntity = xmlSAX2GetEntity; |
| 2983 | hdlr->getParameterEntity = NULL; |
| 2984 | hdlr->entityDecl = xmlSAX2EntityDecl; |
| 2985 | hdlr->attributeDecl = NULL; |
| 2986 | hdlr->elementDecl = NULL; |
| 2987 | hdlr->notationDecl = NULL; |
| 2988 | hdlr->unparsedEntityDecl = NULL; |
| 2989 | hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator; |
| 2990 | hdlr->startDocument = xmlSAX2StartDocument; |
| 2991 | hdlr->endDocument = xmlSAX2EndDocument; |
| 2992 | hdlr->startElement = xmlSAX2StartElement; |
| 2993 | hdlr->endElement = xmlSAX2EndElement; |
| 2994 | hdlr->reference = xmlSAX2Reference; |
| 2995 | hdlr->characters = xmlSAX2Characters; |
| 2996 | hdlr->cdataBlock = NULL; |
| 2997 | hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace; |
| 2998 | hdlr->processingInstruction = NULL; |
| 2999 | hdlr->comment = xmlSAX2Comment; |
| 3000 | hdlr->warning = xmlParserWarning; |
| 3001 | hdlr->error = xmlParserError; |
| 3002 | hdlr->fatalError = xmlParserError; |
| 3003 | |
Daniel Veillard | ffbbed4 | 2003-10-10 14:46:54 +0000 | [diff] [blame] | 3004 | hdlr->initialized = 1; |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | /** |
| 3008 | * docbDefaultSAXHandlerInit: |
| 3009 | * |
| 3010 | * Initialize the default SAX handler |
| 3011 | */ |
| 3012 | void |
| 3013 | docbDefaultSAXHandlerInit(void) |
| 3014 | { |
Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 3015 | xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr) &docbDefaultSAXHandler); |
Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | #endif /* LIBXML_DOCB_ENABLED */ |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 3019 | #define bottom_SAX2 |
| 3020 | #include "elfgcchack.h" |