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