Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SAX.c : Default SAX handler to build a tree. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 6 | * Daniel Veillard <Daniel.Veillard@w3.org> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 9 | |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 10 | #ifdef WIN32 |
| 11 | #include "win32config.h" |
| 12 | #else |
| 13 | #include "config.h" |
| 14 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
Seth Alves | e7f12e6 | 1998-10-01 20:51:15 +0000 | [diff] [blame] | 16 | #include <stdlib.h> |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 17 | #include <string.h> |
Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 18 | #include <libxml/xmlmemory.h> |
| 19 | #include <libxml/tree.h> |
| 20 | #include <libxml/parser.h> |
| 21 | #include <libxml/parserInternals.h> |
| 22 | #include <libxml/valid.h> |
| 23 | #include <libxml/entities.h> |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 24 | #include <libxml/xml-error.h> |
Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 25 | #include <libxml/debugXML.h> |
| 26 | #include <libxml/xmlIO.h> |
| 27 | #include <libxml/SAX.h> |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 28 | #include <libxml/uri.h> |
Daniel Veillard | d83eb82 | 2000-06-30 18:39:56 +0000 | [diff] [blame] | 29 | #include <libxml/HTMLtree.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 30 | |
| 31 | /* #define DEBUG_SAX */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 32 | /* #define DEBUG_SAX_TREE */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 33 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 34 | /** |
| 35 | * getPublicId: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 36 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 37 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 38 | * Return the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN" |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 39 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 40 | * Returns a xmlChar * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 41 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 42 | const xmlChar * |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 43 | getPublicId(void *ctx) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 44 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 45 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 46 | return(NULL); |
| 47 | } |
| 48 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 49 | /** |
| 50 | * getSystemId: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 51 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 52 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 53 | * Return the system ID, basically URL or filename e.g. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 54 | * http://www.sgmlsource.com/dtds/memo.dtd |
| 55 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 56 | * Returns a xmlChar * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 57 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 58 | const xmlChar * |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 59 | getSystemId(void *ctx) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 60 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 61 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 62 | return(BAD_CAST ctxt->input->filename); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 65 | /** |
| 66 | * getLineNumber: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 67 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 68 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 69 | * Return the line number of the current parsing point. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 70 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 71 | * Returns an int |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 72 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 73 | int |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 74 | getLineNumber(void *ctx) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 75 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 76 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 77 | return(ctxt->input->line); |
| 78 | } |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * getColumnNumber: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 82 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 83 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 84 | * Return the column number of the current parsing point. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 85 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 86 | * Returns an int |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 87 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 88 | int |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 89 | getColumnNumber(void *ctx) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 90 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 91 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 92 | return(ctxt->input->col); |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * The default SAX Locator. |
| 97 | */ |
| 98 | |
| 99 | xmlSAXLocator xmlDefaultSAXLocator = { |
| 100 | getPublicId, getSystemId, getLineNumber, getColumnNumber |
| 101 | }; |
| 102 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 103 | /** |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 104 | * isStandalone: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 105 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 106 | * |
| 107 | * Is this document tagged standalone ? |
| 108 | * |
| 109 | * Returns 1 if true |
| 110 | */ |
| 111 | int |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 112 | isStandalone(void *ctx) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 113 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 114 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 115 | return(ctxt->myDoc->standalone == 1); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * hasInternalSubset: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 120 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 121 | * |
| 122 | * Does this document has an internal subset |
| 123 | * |
| 124 | * Returns 1 if true |
| 125 | */ |
| 126 | int |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 127 | hasInternalSubset(void *ctx) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 128 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 129 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 130 | return(ctxt->myDoc->intSubset != NULL); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * hasExternalSubset: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 135 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 136 | * |
| 137 | * Does this document has an external subset |
| 138 | * |
| 139 | * Returns 1 if true |
| 140 | */ |
| 141 | int |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 142 | hasExternalSubset(void *ctx) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 143 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 144 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 145 | return(ctxt->myDoc->extSubset != NULL); |
| 146 | } |
| 147 | |
| 148 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 149 | * internalSubset: |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 150 | * @ctx: the user data (XML parser context) |
| 151 | * @name: the root element name |
| 152 | * @ExternalID: the external ID |
| 153 | * @SystemID: the SYSTEM ID (e.g. filename or URL) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 154 | * |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 155 | * Callback on internal subset declaration. |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 156 | */ |
| 157 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 158 | internalSubset(void *ctx, const xmlChar *name, |
| 159 | const xmlChar *ExternalID, const xmlChar *SystemID) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 160 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 161 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | d83eb82 | 2000-06-30 18:39:56 +0000 | [diff] [blame] | 162 | xmlDtdPtr dtd; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 163 | #ifdef DEBUG_SAX |
| 164 | fprintf(stderr, "SAX.internalSubset(%s, %s, %s)\n", |
| 165 | name, ExternalID, SystemID); |
| 166 | #endif |
Daniel Veillard | d83eb82 | 2000-06-30 18:39:56 +0000 | [diff] [blame] | 167 | |
| 168 | if (ctxt->myDoc == NULL) |
| 169 | return; |
| 170 | dtd = xmlGetIntSubset(ctxt->myDoc); |
| 171 | if (dtd != NULL) { |
| 172 | xmlUnlinkNode((xmlNodePtr) dtd); |
| 173 | xmlFreeDtd(dtd); |
| 174 | ctxt->myDoc->intSubset = NULL; |
| 175 | } |
| 176 | ctxt->myDoc->intSubset = |
| 177 | xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
| 181 | * externalSubset: |
| 182 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 183 | * @name: the root element name |
| 184 | * @ExternalID: the external ID |
| 185 | * @SystemID: the SYSTEM ID (e.g. filename or URL) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 186 | * |
| 187 | * Callback on external subset declaration. |
| 188 | */ |
| 189 | void |
| 190 | externalSubset(void *ctx, const xmlChar *name, |
| 191 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 192 | { |
| 193 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 194 | #ifdef DEBUG_SAX |
| 195 | fprintf(stderr, "SAX.externalSubset(%s, %s, %s)\n", |
| 196 | name, ExternalID, SystemID); |
| 197 | #endif |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 198 | if (((ExternalID != NULL) || (SystemID != NULL)) && |
| 199 | (ctxt->validate && ctxt->wellFormed && ctxt->myDoc)) { |
| 200 | /* |
| 201 | * Try to fetch and parse the external subset. |
| 202 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 203 | xmlParserInputPtr oldinput; |
| 204 | int oldinputNr; |
| 205 | int oldinputMax; |
| 206 | xmlParserInputPtr *oldinputTab; |
| 207 | int oldwellFormed; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 208 | xmlParserInputPtr input = NULL; |
| 209 | xmlCharEncoding enc; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 210 | int oldcharset; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 211 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 212 | /* |
| 213 | * Ask the Entity resolver to load the damn thing |
| 214 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 215 | if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) |
| 216 | input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 217 | SystemID); |
| 218 | if (input == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 219 | return; |
| 220 | } |
| 221 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 222 | xmlNewDtd(ctxt->myDoc, name, ExternalID, SystemID); |
| 223 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 224 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 225 | * make sure we won't destroy the main document context |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 226 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 227 | oldinput = ctxt->input; |
| 228 | oldinputNr = ctxt->inputNr; |
| 229 | oldinputMax = ctxt->inputMax; |
| 230 | oldinputTab = ctxt->inputTab; |
| 231 | oldwellFormed = ctxt->wellFormed; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 232 | oldcharset = ctxt->charset; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 233 | |
| 234 | ctxt->inputTab = (xmlParserInputPtr *) |
| 235 | xmlMalloc(5 * sizeof(xmlParserInputPtr)); |
| 236 | if (ctxt->inputTab == NULL) { |
| 237 | ctxt->errNo = XML_ERR_NO_MEMORY; |
| 238 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 239 | ctxt->sax->error(ctxt->userData, |
| 240 | "externalSubset: out of memory\n"); |
| 241 | ctxt->errNo = XML_ERR_NO_MEMORY; |
| 242 | ctxt->input = oldinput; |
| 243 | ctxt->inputNr = oldinputNr; |
| 244 | ctxt->inputMax = oldinputMax; |
| 245 | ctxt->inputTab = oldinputTab; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 246 | ctxt->charset = oldcharset; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 247 | return; |
| 248 | } |
| 249 | ctxt->inputNr = 0; |
| 250 | ctxt->inputMax = 5; |
| 251 | ctxt->input = NULL; |
| 252 | xmlPushInput(ctxt, input); |
| 253 | |
| 254 | /* |
| 255 | * On the fly encoding conversion if needed |
| 256 | */ |
| 257 | enc = xmlDetectCharEncoding(ctxt->input->cur, 4); |
| 258 | xmlSwitchEncoding(ctxt, enc); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 259 | |
| 260 | if (input->filename == NULL) |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 261 | input->filename = (char *) xmlStrdup(SystemID); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 262 | input->line = 1; |
| 263 | input->col = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 264 | input->base = ctxt->input->cur; |
| 265 | input->cur = ctxt->input->cur; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 266 | input->free = NULL; |
| 267 | |
| 268 | /* |
| 269 | * let's parse that entity knowing it's an external subset. |
| 270 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 271 | xmlParseExternalSubset(ctxt, ExternalID, SystemID); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 272 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 273 | /* |
| 274 | * Free up the external entities |
| 275 | */ |
| 276 | |
| 277 | while (ctxt->inputNr > 1) |
| 278 | xmlPopInput(ctxt); |
| 279 | xmlFreeInputStream(ctxt->input); |
| 280 | xmlFree(ctxt->inputTab); |
| 281 | |
| 282 | /* |
| 283 | * Restore the parsing context of the main entity |
| 284 | */ |
| 285 | ctxt->input = oldinput; |
| 286 | ctxt->inputNr = oldinputNr; |
| 287 | ctxt->inputMax = oldinputMax; |
| 288 | ctxt->inputTab = oldinputTab; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 289 | ctxt->charset = oldcharset; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 290 | /* ctxt->wellFormed = oldwellFormed; */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 291 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 295 | * resolveEntity: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 296 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 297 | * @publicId: The public ID of the entity |
| 298 | * @systemId: The system ID of the entity |
| 299 | * |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 300 | * The entity loader, to control the loading of external entities, |
| 301 | * the application can either: |
| 302 | * - override this resolveEntity() callback in the SAX block |
| 303 | * - or better use the xmlSetExternalEntityLoader() function to |
| 304 | * set up it's own entity resolution routine |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 305 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 306 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 307 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 308 | xmlParserInputPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 309 | resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 310 | { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 311 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 312 | |
| 313 | #ifdef DEBUG_SAX |
| 314 | fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId); |
| 315 | #endif |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 316 | |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 317 | return(xmlLoadExternalEntity((const char *) systemId, |
| 318 | (const char *) publicId, ctxt)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 321 | /** |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 322 | * getEntity: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 323 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 324 | * @name: The entity name |
| 325 | * |
| 326 | * Get an entity by name |
| 327 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 328 | * Returns the xmlEntityPtr if found. |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 329 | */ |
| 330 | xmlEntityPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 331 | getEntity(void *ctx, const xmlChar *name) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 332 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 333 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 334 | xmlEntityPtr ret; |
| 335 | |
| 336 | #ifdef DEBUG_SAX |
| 337 | fprintf(stderr, "SAX.getEntity(%s)\n", name); |
| 338 | #endif |
| 339 | |
| 340 | ret = xmlGetDocEntity(ctxt->myDoc, name); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame^] | 341 | if ((ret != NULL) && (ctxt->validate) && (ret->children == NULL) && |
| 342 | (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { |
| 343 | /* |
| 344 | * for validation purposes we really need to fetch and |
| 345 | * parse the external entity |
| 346 | */ |
| 347 | int parse; |
| 348 | xmlNodePtr children; |
| 349 | |
| 350 | parse = xmlParseCtxtExternalEntity(ctxt, |
| 351 | ret->SystemID, ret->ExternalID, &children); |
| 352 | xmlAddChildList((xmlNodePtr) ret, children); |
| 353 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 354 | return(ret); |
| 355 | } |
| 356 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 357 | /** |
| 358 | * getParameterEntity: |
| 359 | * @ctx: the user data (XML parser context) |
| 360 | * @name: The entity name |
| 361 | * |
| 362 | * Get a parameter entity by name |
| 363 | * |
| 364 | * Returns the xmlEntityPtr if found. |
| 365 | */ |
| 366 | xmlEntityPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 367 | getParameterEntity(void *ctx, const xmlChar *name) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 368 | { |
| 369 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 370 | xmlEntityPtr ret; |
| 371 | |
| 372 | #ifdef DEBUG_SAX |
| 373 | fprintf(stderr, "SAX.getParameterEntity(%s)\n", name); |
| 374 | #endif |
| 375 | |
| 376 | ret = xmlGetParameterEntity(ctxt->myDoc, name); |
| 377 | return(ret); |
| 378 | } |
| 379 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 380 | |
| 381 | /** |
| 382 | * entityDecl: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 383 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 384 | * @name: the entity name |
| 385 | * @type: the entity type |
| 386 | * @publicId: The public ID of the entity |
| 387 | * @systemId: The system ID of the entity |
| 388 | * @content: the entity value (without processing). |
| 389 | * |
| 390 | * An entity definition has been parsed |
| 391 | */ |
| 392 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 393 | entityDecl(void *ctx, const xmlChar *name, int type, |
| 394 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 395 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 396 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 397 | |
| 398 | #ifdef DEBUG_SAX |
| 399 | fprintf(stderr, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", |
| 400 | name, type, publicId, systemId, content); |
| 401 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 402 | if (ctxt->inSubset == 1) |
| 403 | xmlAddDocEntity(ctxt->myDoc, name, type, publicId, |
| 404 | systemId, content); |
| 405 | else if (ctxt->inSubset == 2) |
| 406 | xmlAddDtdEntity(ctxt->myDoc, name, type, publicId, |
| 407 | systemId, content); |
| 408 | else { |
| 409 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 410 | ctxt->sax->error(ctxt, |
| 411 | "SAX.entityDecl(%s) called while not in subset\n", name); |
| 412 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
| 416 | * attributeDecl: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 417 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 418 | * @elem: the name of the element |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 419 | * @fullname: the attribute name |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 420 | * @type: the attribute type |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 421 | * @def: the type of default value |
| 422 | * @defaultValue: the attribute default value |
| 423 | * @tree: the tree of enumerated value set |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 424 | * |
| 425 | * An attribute definition has been parsed |
| 426 | */ |
| 427 | void |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 428 | attributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 429 | int type, int def, const xmlChar *defaultValue, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 430 | xmlEnumerationPtr tree) |
| 431 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 432 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 433 | xmlAttributePtr attr; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 434 | xmlChar *name = NULL, *prefix = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 435 | |
| 436 | #ifdef DEBUG_SAX |
| 437 | fprintf(stderr, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 438 | elem, fullname, type, def, defaultValue); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 439 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 440 | name = xmlSplitQName(ctxt, fullname, &prefix); |
| 441 | if (ctxt->inSubset == 1) |
| 442 | attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem, |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 443 | name, prefix, (xmlAttributeType) type, |
| 444 | (xmlAttributeDefault) def, defaultValue, tree); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 445 | else if (ctxt->inSubset == 2) |
| 446 | attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem, |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 447 | name, prefix, (xmlAttributeType) type, |
| 448 | (xmlAttributeDefault) def, defaultValue, tree); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 449 | else { |
| 450 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 451 | ctxt->sax->error(ctxt, |
| 452 | "SAX.attributeDecl(%s) called while not in subset\n", name); |
| 453 | return; |
| 454 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 455 | if (attr == 0) ctxt->valid = 0; |
| 456 | if (ctxt->validate && ctxt->wellFormed && |
| 457 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 458 | ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, |
| 459 | attr); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 460 | if (prefix != NULL) |
| 461 | xmlFree(prefix); |
| 462 | if (name != NULL) |
| 463 | xmlFree(name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /** |
| 467 | * elementDecl: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 468 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 469 | * @name: the element name |
| 470 | * @type: the element type |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 471 | * @content: the element value tree |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 472 | * |
| 473 | * An element definition has been parsed |
| 474 | */ |
| 475 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 476 | elementDecl(void *ctx, const xmlChar *name, int type, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 477 | xmlElementContentPtr content) |
| 478 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 479 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 480 | xmlElementPtr elem = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 481 | |
| 482 | #ifdef DEBUG_SAX |
| 483 | fprintf(stderr, "SAX.elementDecl(%s, %d, ...)\n", |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 484 | fullname, type); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 485 | #endif |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 486 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 487 | if (ctxt->inSubset == 1) |
| 488 | elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 489 | name, (xmlElementTypeVal) type, content); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 490 | else if (ctxt->inSubset == 2) |
| 491 | elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 492 | name, (xmlElementTypeVal) type, content); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 493 | else { |
| 494 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 495 | ctxt->sax->error(ctxt, |
| 496 | "SAX.elementDecl(%s) called while not in subset\n", name); |
| 497 | return; |
| 498 | } |
| 499 | if (elem == NULL) ctxt->valid = 0; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 500 | if (ctxt->validate && ctxt->wellFormed && |
| 501 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 502 | ctxt->valid &= xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 506 | * notationDecl: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 507 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 508 | * @name: The name of the notation |
| 509 | * @publicId: The public ID of the entity |
| 510 | * @systemId: The system ID of the entity |
| 511 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 512 | * What to do when a notation declaration has been parsed. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 513 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 514 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 515 | notationDecl(void *ctx, const xmlChar *name, |
| 516 | const xmlChar *publicId, const xmlChar *systemId) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 517 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 518 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 519 | xmlNotationPtr nota = NULL; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 520 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 521 | #ifdef DEBUG_SAX |
| 522 | fprintf(stderr, "SAX.notationDecl(%s, %s, %s)\n", name, publicId, systemId); |
| 523 | #endif |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 524 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 525 | if (ctxt->inSubset == 1) |
| 526 | nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 527 | publicId, systemId); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 528 | else if (ctxt->inSubset == 2) |
| 529 | nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name, |
| 530 | publicId, systemId); |
| 531 | else { |
| 532 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 533 | ctxt->sax->error(ctxt, |
| 534 | "SAX.notationDecl(%s) called while not in subset\n", name); |
| 535 | return; |
| 536 | } |
| 537 | if (nota == NULL) ctxt->valid = 0; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 538 | if (ctxt->validate && ctxt->wellFormed && |
| 539 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 540 | ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc, |
| 541 | nota); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 544 | /** |
| 545 | * unparsedEntityDecl: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 546 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 547 | * @name: The name of the entity |
| 548 | * @publicId: The public ID of the entity |
| 549 | * @systemId: The system ID of the entity |
| 550 | * @notationName: the name of the notation |
| 551 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 552 | * What to do when an unparsed entity declaration is parsed |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 553 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 554 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 555 | unparsedEntityDecl(void *ctx, const xmlChar *name, |
| 556 | const xmlChar *publicId, const xmlChar *systemId, |
| 557 | const xmlChar *notationName) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 558 | { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 559 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 560 | #ifdef DEBUG_SAX |
| 561 | fprintf(stderr, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", |
| 562 | name, publicId, systemId, notationName); |
| 563 | #endif |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 564 | if (ctxt->validate && ctxt->wellFormed && |
| 565 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 566 | ctxt->valid &= xmlValidateNotationUse(&ctxt->vctxt, ctxt->myDoc, |
| 567 | notationName); |
| 568 | xmlAddDocEntity(ctxt->myDoc, name, |
| 569 | XML_EXTERNAL_GENERAL_UNPARSED_ENTITY, |
| 570 | publicId, systemId, notationName); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 573 | /** |
| 574 | * setDocumentLocator: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 575 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 576 | * @loc: A SAX Locator |
| 577 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 578 | * Receive the document locator at startup, actually xmlDefaultSAXLocator |
| 579 | * Everything is available on the context, so this is useless in our case. |
| 580 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 581 | void |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 582 | setDocumentLocator(void *ctx, xmlSAXLocatorPtr loc) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 583 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 584 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 585 | #ifdef DEBUG_SAX |
| 586 | fprintf(stderr, "SAX.setDocumentLocator()\n"); |
| 587 | #endif |
| 588 | } |
| 589 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 590 | /** |
| 591 | * startDocument: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 592 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 593 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 594 | * called when the document start being processed. |
| 595 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 596 | void |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 597 | startDocument(void *ctx) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 598 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 599 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 600 | xmlDocPtr doc; |
| 601 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 602 | #ifdef DEBUG_SAX |
| 603 | fprintf(stderr, "SAX.startDocument()\n"); |
| 604 | #endif |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 605 | if (ctxt->html) { |
| 606 | if (ctxt->myDoc == NULL) |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame^] | 607 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 608 | ctxt->myDoc = htmlNewDoc(NULL, NULL); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame^] | 609 | #else |
| 610 | fprintf(stderr, "libxml2 built without HTML support\n"); |
| 611 | #endif |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 612 | } else { |
| 613 | doc = ctxt->myDoc = xmlNewDoc(ctxt->version); |
| 614 | if (doc != NULL) { |
| 615 | if (ctxt->encoding != NULL) |
| 616 | doc->encoding = xmlStrdup(ctxt->encoding); |
| 617 | else |
| 618 | doc->encoding = NULL; |
| 619 | doc->standalone = ctxt->standalone; |
| 620 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 621 | } |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame^] | 622 | if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) && |
| 623 | (ctxt->input != NULL) && (ctxt->input->filename != NULL)) { |
| 624 | ctxt->myDoc->URL = xmlStrdup((xmlChar *) ctxt->input->filename); |
| 625 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 628 | /** |
| 629 | * endDocument: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 630 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 631 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 632 | * called when the document end has been detected. |
| 633 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 634 | void |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 635 | endDocument(void *ctx) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 636 | { |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 637 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 638 | #ifdef DEBUG_SAX |
| 639 | fprintf(stderr, "SAX.endDocument()\n"); |
| 640 | #endif |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 641 | if (ctxt->validate && ctxt->wellFormed && |
| 642 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 643 | ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * Grab the encoding if it was added on-the-fly |
| 647 | */ |
| 648 | if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) && |
| 649 | (ctxt->myDoc->encoding == NULL)) { |
| 650 | ctxt->myDoc->encoding = ctxt->encoding; |
| 651 | ctxt->encoding = NULL; |
| 652 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 653 | if ((ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) && |
| 654 | (ctxt->myDoc->encoding == NULL)) { |
| 655 | ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding); |
| 656 | } |
| 657 | if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) && |
| 658 | (ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) { |
| 659 | ctxt->myDoc->charset = ctxt->charset; |
| 660 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 663 | /** |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 664 | * attribute: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 665 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 666 | * @fullname: The attribute name, including namespace prefix |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 667 | * @value: The attribute value |
| 668 | * |
| 669 | * Handle an attribute that has been read by the parser. |
| 670 | * The default handling is to convert the attribute into an |
| 671 | * DOM subtree and past it in a new xmlAttr element added to |
| 672 | * the element. |
| 673 | */ |
| 674 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 675 | attribute(void *ctx, const xmlChar *fullname, const xmlChar *value) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 676 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 677 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 678 | xmlAttrPtr ret; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 679 | xmlChar *name; |
| 680 | xmlChar *ns; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 681 | xmlChar *nval; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 682 | xmlNsPtr namespace; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 683 | |
| 684 | /**************** |
| 685 | #ifdef DEBUG_SAX |
| 686 | fprintf(stderr, "SAX.attribute(%s, %s)\n", fullname, value); |
| 687 | #endif |
| 688 | ****************/ |
| 689 | /* |
| 690 | * Split the full name into a namespace prefix and the tag name |
| 691 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 692 | name = xmlSplitQName(ctxt, fullname, &ns); |
| 693 | |
| 694 | /* |
| 695 | * Do the last stave of the attribute normalization |
| 696 | */ |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 697 | if (ctxt->html) |
| 698 | nval = NULL; |
| 699 | else |
| 700 | nval = xmlValidNormalizeAttributeValue(ctxt->myDoc, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 701 | ctxt->node, fullname, value); |
| 702 | if (nval != NULL) |
| 703 | value = nval; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 704 | |
| 705 | /* |
| 706 | * Check whether it's a namespace definition |
| 707 | */ |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 708 | if ((!ctxt->html) && (ns == NULL) && |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 709 | (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') && |
| 710 | (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 711 | xmlURIPtr uri; |
| 712 | |
| 713 | uri = xmlParseURI((const char *)value); |
| 714 | if (uri == NULL) { |
| 715 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 716 | ctxt->sax->warning(ctxt->userData, |
| 717 | "nmlns: %s not a valid URI\n", value); |
| 718 | } else { |
| 719 | if (uri->scheme == NULL) { |
| 720 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 721 | ctxt->sax->warning(ctxt->userData, |
| 722 | "nmlns: URI %s is not absolute\n", value); |
| 723 | } |
| 724 | xmlFreeURI(uri); |
| 725 | } |
| 726 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 727 | /* a default namespace definition */ |
| 728 | xmlNewNs(ctxt->node, value, NULL); |
| 729 | if (name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 730 | xmlFree(name); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 731 | if (nval != NULL) |
| 732 | xmlFree(nval); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 733 | return; |
| 734 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 735 | if ((!ctxt->html) && |
| 736 | (ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') && |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 737 | (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 738 | /* |
| 739 | * Validate also for namespace decls, they are attributes from |
| 740 | * an XML-1.0 perspective |
| 741 | TODO ... doesn't map well with current API |
| 742 | if (ctxt->validate && ctxt->wellFormed && |
| 743 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 744 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc, |
| 745 | ctxt->node, ret, value); |
| 746 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 747 | /* a standard namespace definition */ |
| 748 | xmlNewNs(ctxt->node, value, name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 749 | xmlFree(ns); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 750 | if (name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 751 | xmlFree(name); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 752 | if (nval != NULL) |
| 753 | xmlFree(nval); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
Daniel Veillard | 5cb5ab8 | 1999-12-21 15:35:29 +0000 | [diff] [blame] | 757 | if (ns != NULL) |
| 758 | namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns); |
| 759 | else { |
| 760 | namespace = NULL; |
| 761 | } |
| 762 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 763 | /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */ |
| 764 | ret = xmlNewNsProp(ctxt->node, namespace, name, NULL); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 765 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 766 | if (ret != NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 767 | if ((ctxt->replaceEntities == 0) && (!ctxt->html)) { |
| 768 | xmlNodePtr tmp; |
| 769 | |
| 770 | ret->children = xmlStringGetNodeList(ctxt->myDoc, value); |
| 771 | tmp = ret->children; |
| 772 | while (tmp != NULL) { |
| 773 | tmp->parent = (xmlNodePtr) ret; |
| 774 | if (tmp->next == NULL) |
| 775 | ret->last = tmp; |
| 776 | tmp = tmp->next; |
| 777 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 778 | } else if (value != NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 779 | ret->children = xmlNewDocText(ctxt->myDoc, value); |
| 780 | ret->last = ret->children; |
| 781 | if (ret->children != NULL) |
| 782 | ret->children->parent = (xmlNodePtr) ret; |
| 783 | } |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 784 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 785 | |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 786 | if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 787 | ctxt->myDoc && ctxt->myDoc->intSubset) { |
| 788 | |
| 789 | /* |
| 790 | * If we don't substitute entities, the validation should be |
| 791 | * done on a value with replaced entities anyway. |
| 792 | */ |
| 793 | if (!ctxt->replaceEntities) { |
| 794 | xmlChar *val; |
| 795 | |
| 796 | ctxt->depth++; |
| 797 | val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF, |
| 798 | 0,0,0); |
| 799 | ctxt->depth--; |
| 800 | if (val == NULL) |
| 801 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 802 | ctxt->myDoc, ctxt->node, ret, value); |
| 803 | else { |
| 804 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, |
| 805 | ctxt->myDoc, ctxt->node, ret, val); |
| 806 | xmlFree(val); |
| 807 | } |
| 808 | } else { |
| 809 | ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 810 | ctxt->node, ret, value); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 811 | } |
| 812 | } else { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 813 | /* |
| 814 | * when validating, the ID registration is done at the attribute |
| 815 | * validation level. Otherwise we have to do specific handling here. |
| 816 | */ |
| 817 | if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) |
| 818 | xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 819 | else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) |
| 820 | xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 821 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 822 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 823 | if (nval != NULL) |
| 824 | xmlFree(nval); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 825 | if (name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 826 | xmlFree(name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 827 | if (ns != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 828 | xmlFree(ns); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 832 | * startElement: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 833 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 834 | * @fullname: The element name, including namespace prefix |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 835 | * @atts: An array of name/value attributes pairs, NULL terminated |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 836 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 837 | * called when an opening tag has been processed. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 838 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 839 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 840 | startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 841 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 842 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 843 | xmlNodePtr ret; |
| 844 | xmlNodePtr parent = ctxt->node; |
| 845 | xmlNsPtr ns; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 846 | xmlChar *name; |
| 847 | xmlChar *prefix; |
| 848 | const xmlChar *att; |
| 849 | const xmlChar *value; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 850 | int i; |
| 851 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 852 | #ifdef DEBUG_SAX |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 853 | fprintf(stderr, "SAX.startElement(%s)\n", fullname); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 854 | #endif |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 855 | |
| 856 | /* |
| 857 | * First check on validity: |
| 858 | */ |
| 859 | if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && |
| 860 | ((ctxt->myDoc->intSubset == NULL) || |
| 861 | ((ctxt->myDoc->intSubset->notations == NULL) && |
| 862 | (ctxt->myDoc->intSubset->elements == NULL) && |
| 863 | (ctxt->myDoc->intSubset->attributes == NULL) && |
| 864 | (ctxt->myDoc->intSubset->entities == NULL)))) { |
| 865 | if (ctxt->vctxt.error != NULL) { |
| 866 | ctxt->vctxt.error(ctxt->vctxt.userData, |
| 867 | "Validation failed: no DTD found !\n"); |
| 868 | } |
| 869 | ctxt->validate = 0; |
| 870 | } |
| 871 | |
| 872 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 873 | /* |
| 874 | * Split the full name into a namespace prefix and the tag name |
| 875 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 876 | name = xmlSplitQName(ctxt, fullname, &prefix); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 877 | |
| 878 | |
| 879 | /* |
| 880 | * Note : the namespace resolution is deferred until the end of the |
| 881 | * attributes parsing, since local namespace can be defined as |
| 882 | * an attribute at this level. |
| 883 | */ |
| 884 | ret = xmlNewDocNode(ctxt->myDoc, NULL, name, NULL); |
| 885 | if (ret == NULL) return; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 886 | if (ctxt->myDoc->children == NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 887 | #ifdef DEBUG_SAX_TREE |
| 888 | fprintf(stderr, "Setting %s as root\n", name); |
| 889 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 890 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 891 | } else if (parent == NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 892 | parent = ctxt->myDoc->children; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 893 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 894 | ctxt->nodemem = -1; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 895 | |
| 896 | /* |
| 897 | * We are parsing a new node. |
| 898 | */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 899 | #ifdef DEBUG_SAX_TREE |
| 900 | fprintf(stderr, "pushing(%s)\n", name); |
| 901 | #endif |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 902 | nodePush(ctxt, ret); |
| 903 | |
| 904 | /* |
| 905 | * Link the child element |
| 906 | */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 907 | if (parent != NULL) { |
| 908 | if (parent->type == XML_ELEMENT_NODE) { |
| 909 | #ifdef DEBUG_SAX_TREE |
| 910 | fprintf(stderr, "adding child %s to %s\n", name, parent->name); |
| 911 | #endif |
| 912 | xmlAddChild(parent, ret); |
| 913 | } else { |
| 914 | #ifdef DEBUG_SAX_TREE |
| 915 | fprintf(stderr, "adding sibling %s to ", name); |
| 916 | xmlDebugDumpOneNode(stderr, parent, 0); |
| 917 | #endif |
| 918 | xmlAddSibling(parent, ret); |
| 919 | } |
| 920 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 921 | |
| 922 | /* |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 923 | * process all the attributes whose name start with "xml" |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 924 | */ |
| 925 | if (atts != NULL) { |
| 926 | i = 0; |
| 927 | att = atts[i++]; |
| 928 | value = atts[i++]; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 929 | if (!ctxt->html) { |
| 930 | while ((att != NULL) && (value != NULL)) { |
| 931 | if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l')) |
| 932 | attribute(ctxt, att, value); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 933 | |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 934 | att = atts[i++]; |
| 935 | value = atts[i++]; |
| 936 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
| 940 | /* |
| 941 | * Search the namespace, note that since the attributes have been |
| 942 | * processed, the local namespaces are available. |
| 943 | */ |
| 944 | ns = xmlSearchNs(ctxt->myDoc, ret, prefix); |
| 945 | if ((ns == NULL) && (parent != NULL)) |
| 946 | ns = xmlSearchNs(ctxt->myDoc, parent, prefix); |
| 947 | xmlSetNs(ret, ns); |
| 948 | |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 949 | /* |
| 950 | * process all the other attributes |
| 951 | */ |
| 952 | if (atts != NULL) { |
| 953 | i = 0; |
| 954 | att = atts[i++]; |
| 955 | value = atts[i++]; |
| 956 | if (ctxt->html) { |
| 957 | while (att != NULL) { |
| 958 | attribute(ctxt, att, value); |
| 959 | att = atts[i++]; |
| 960 | value = atts[i++]; |
| 961 | } |
| 962 | } else { |
| 963 | while ((att != NULL) && (value != NULL)) { |
| 964 | if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l')) |
| 965 | attribute(ctxt, att, value); |
| 966 | |
| 967 | /* |
| 968 | * Next ones |
| 969 | */ |
| 970 | att = atts[i++]; |
| 971 | value = atts[i++]; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | /* |
| 977 | * If it's the Document root, finish the Dtd validation and |
| 978 | * check the document root element for validity |
| 979 | */ |
| 980 | if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) { |
| 981 | ctxt->valid &= xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); |
| 982 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); |
| 983 | ctxt->vctxt.finishDtd = 1; |
| 984 | } |
| 985 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 986 | if (prefix != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 987 | xmlFree(prefix); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 988 | if (name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 989 | xmlFree(name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 990 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 993 | /** |
| 994 | * endElement: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 995 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 996 | * @name: The element name |
| 997 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 998 | * called when the end of an element has been detected. |
| 999 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1000 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1001 | endElement(void *ctx, const xmlChar *name) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1002 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1003 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1004 | xmlParserNodeInfo node_info; |
| 1005 | xmlNodePtr cur = ctxt->node; |
| 1006 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1007 | #ifdef DEBUG_SAX |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1008 | if (name == NULL) |
| 1009 | fprintf(stderr, "SAX.endElement(NULL)\n"); |
| 1010 | else |
| 1011 | fprintf(stderr, "SAX.endElement(%s)\n", name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1012 | #endif |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1013 | |
| 1014 | /* Capture end position and add node */ |
| 1015 | if (cur != NULL && ctxt->record_info) { |
| 1016 | node_info.end_pos = ctxt->input->cur - ctxt->input->base; |
| 1017 | node_info.end_line = ctxt->input->line; |
| 1018 | node_info.node = cur; |
| 1019 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 1020 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1021 | ctxt->nodemem = -1; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1022 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1023 | if (ctxt->validate && ctxt->wellFormed && |
| 1024 | ctxt->myDoc && ctxt->myDoc->intSubset) |
| 1025 | ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, |
| 1026 | cur); |
| 1027 | |
| 1028 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1029 | /* |
| 1030 | * end of parsing of this node. |
| 1031 | */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1032 | #ifdef DEBUG_SAX_TREE |
| 1033 | fprintf(stderr, "popping(%s)\n", cur->name); |
| 1034 | #endif |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1035 | nodePop(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1038 | /** |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1039 | * reference: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1040 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1041 | * @name: The entity name |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1042 | * |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1043 | * called when an entity reference is detected. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1044 | */ |
| 1045 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1046 | reference(void *ctx, const xmlChar *name) |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1047 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1048 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1049 | xmlNodePtr ret; |
| 1050 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1051 | #ifdef DEBUG_SAX |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1052 | fprintf(stderr, "SAX.reference(%s)\n", name); |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1053 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1054 | if (name[0] == '#') |
| 1055 | ret = xmlNewCharRef(ctxt->myDoc, name); |
| 1056 | else |
| 1057 | ret = xmlNewReference(ctxt->myDoc, name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1058 | #ifdef DEBUG_SAX_TREE |
| 1059 | fprintf(stderr, "add reference %s to %s \n", name, ctxt->node->name); |
| 1060 | #endif |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1061 | xmlAddChild(ctxt->node, ret); |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1065 | * characters: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1066 | * @ctx: the user data (XML parser context) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1067 | * @ch: a xmlChar string |
| 1068 | * @len: the number of xmlChar |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1069 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1070 | * receiving some chars from the parser. |
| 1071 | * Question: how much at a time ??? |
| 1072 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1073 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1074 | characters(void *ctx, const xmlChar *ch, int len) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1075 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1076 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1077 | xmlNodePtr lastChild; |
| 1078 | |
| 1079 | #ifdef DEBUG_SAX |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1080 | fprintf(stderr, "SAX.characters(%.30s, %d)\n", ch, len); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1081 | #endif |
| 1082 | /* |
| 1083 | * Handle the data if any. If there is no child |
| 1084 | * add it as content, otherwise if the last child is text, |
| 1085 | * concatenate it, else create a new node of type text. |
| 1086 | */ |
| 1087 | |
Daniel Veillard | 3500838 | 1999-10-25 13:15:52 +0000 | [diff] [blame] | 1088 | if (ctxt->node == NULL) { |
| 1089 | #ifdef DEBUG_SAX_TREE |
| 1090 | fprintf(stderr, "add chars: ctxt->node == NULL !\n"); |
| 1091 | #endif |
| 1092 | return; |
| 1093 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1094 | lastChild = xmlGetLastChild(ctxt->node); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1095 | #ifdef DEBUG_SAX_TREE |
| 1096 | fprintf(stderr, "add chars to %s \n", ctxt->node->name); |
| 1097 | #endif |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1098 | |
| 1099 | /* |
| 1100 | * Here we needed an accelerator mechanism in case of very large |
| 1101 | * elements. Use an attribute in the structure !!! |
| 1102 | */ |
| 1103 | if (lastChild == NULL) { |
| 1104 | /* first node, first time */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1105 | xmlNodeAddContentLen(ctxt->node, ch, len); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1106 | #ifndef XML_USE_BUFFER_CONTENT |
| 1107 | if (ctxt->node->children != NULL) { |
| 1108 | ctxt->nodelen = len; |
| 1109 | ctxt->nodemem = len + 1; |
| 1110 | } |
| 1111 | #endif |
| 1112 | } else { |
| 1113 | if (xmlNodeIsText(lastChild)) { |
| 1114 | #ifndef XML_USE_BUFFER_CONTENT |
| 1115 | /* |
| 1116 | * The whole point of maintaining nodelen and nodemem, |
| 1117 | * xmlTextConcat is too costly, i.e. compute lenght, |
| 1118 | * reallocate a new buffer, move data, append ch. Here |
| 1119 | * We try to minimaze realloc() uses and avoid copying |
| 1120 | * and recomputing lenght over and over. |
| 1121 | */ |
| 1122 | if (ctxt->nodelen + len >= ctxt->nodemem) { |
| 1123 | xmlChar *newbuf; |
| 1124 | int size; |
| 1125 | |
| 1126 | size = ctxt->nodemem + len; |
| 1127 | size *= 2; |
| 1128 | newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); |
| 1129 | if (newbuf == NULL) { |
| 1130 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1131 | ctxt->sax->error(ctxt->userData, |
| 1132 | "SAX.characters(): out of memory\n"); |
| 1133 | return; |
| 1134 | } |
| 1135 | ctxt->nodemem = size; |
| 1136 | lastChild->content = newbuf; |
| 1137 | } |
| 1138 | memcpy(&lastChild->content[ctxt->nodelen], ch, len); |
| 1139 | ctxt->nodelen += len; |
| 1140 | lastChild->content[ctxt->nodelen] = 0; |
| 1141 | #else |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1142 | xmlTextConcat(lastChild, ch, len); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1143 | #endif |
| 1144 | } else { |
| 1145 | /* Mixed content, first time */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1146 | lastChild = xmlNewTextLen(ch, len); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1147 | xmlAddChild(ctxt->node, lastChild); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1148 | #ifndef XML_USE_BUFFER_CONTENT |
| 1149 | if (ctxt->node->children != NULL) { |
| 1150 | ctxt->nodelen = len; |
| 1151 | ctxt->nodemem = len + 1; |
| 1152 | } |
| 1153 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1158 | /** |
| 1159 | * ignorableWhitespace: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1160 | * @ctx: the user data (XML parser context) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1161 | * @ch: a xmlChar string |
| 1162 | * @len: the number of xmlChar |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1163 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1164 | * receiving some ignorable whitespaces from the parser. |
| 1165 | * Question: how much at a time ??? |
| 1166 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1167 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1168 | ignorableWhitespace(void *ctx, const xmlChar *ch, int len) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1169 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1170 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1171 | #ifdef DEBUG_SAX |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1172 | fprintf(stderr, "SAX.ignorableWhitespace(%.30s, %d)\n", ch, len); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1173 | #endif |
| 1174 | } |
| 1175 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1176 | /** |
| 1177 | * processingInstruction: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1178 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1179 | * @target: the target name |
| 1180 | * @data: the PI data's |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1181 | * |
| 1182 | * A processing instruction has been parsed. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1183 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1184 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1185 | processingInstruction(void *ctx, const xmlChar *target, |
| 1186 | const xmlChar *data) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1187 | { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1188 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 1189 | xmlNodePtr ret; |
| 1190 | xmlNodePtr parent = ctxt->node; |
| 1191 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1192 | #ifdef DEBUG_SAX |
| 1193 | fprintf(stderr, "SAX.processingInstruction(%s, %s)\n", target, data); |
| 1194 | #endif |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1195 | |
| 1196 | ret = xmlNewPI(target, data); |
| 1197 | if (ret == NULL) return; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1198 | parent = ctxt->node; |
| 1199 | |
| 1200 | if (ctxt->inSubset == 1) { |
| 1201 | xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret); |
| 1202 | return; |
| 1203 | } else if (ctxt->inSubset == 2) { |
| 1204 | xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret); |
| 1205 | return; |
| 1206 | } |
| 1207 | if ((ctxt->myDoc->children == NULL) || (parent == NULL)) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1208 | #ifdef DEBUG_SAX_TREE |
| 1209 | fprintf(stderr, "Setting PI %s as root\n", target); |
| 1210 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1211 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
| 1212 | return; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1213 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1214 | if (parent->type == XML_ELEMENT_NODE) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1215 | #ifdef DEBUG_SAX_TREE |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1216 | fprintf(stderr, "adding PI %s child to %s\n", target, parent->name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1217 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1218 | xmlAddChild(parent, ret); |
| 1219 | } else { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1220 | #ifdef DEBUG_SAX_TREE |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1221 | fprintf(stderr, "adding PI %s sibling to ", target); |
| 1222 | xmlDebugDumpOneNode(stderr, parent, 0); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1223 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1224 | xmlAddSibling(parent, ret); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1225 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1228 | /** |
| 1229 | * globalNamespace: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1230 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1231 | * @href: the namespace associated URN |
| 1232 | * @prefix: the namespace prefix |
| 1233 | * |
| 1234 | * An old global namespace has been parsed. |
| 1235 | */ |
| 1236 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1237 | globalNamespace(void *ctx, const xmlChar *href, const xmlChar *prefix) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1238 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1239 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1240 | #ifdef DEBUG_SAX |
| 1241 | fprintf(stderr, "SAX.globalNamespace(%s, %s)\n", href, prefix); |
| 1242 | #endif |
| 1243 | xmlNewGlobalNs(ctxt->myDoc, href, prefix); |
| 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * setNamespace: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1248 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1249 | * @name: the namespace prefix |
| 1250 | * |
| 1251 | * Set the current element namespace. |
| 1252 | */ |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 1253 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1254 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1255 | setNamespace(void *ctx, const xmlChar *name) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1256 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1257 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1258 | xmlNsPtr ns; |
| 1259 | xmlNodePtr parent; |
| 1260 | |
| 1261 | #ifdef DEBUG_SAX |
| 1262 | fprintf(stderr, "SAX.setNamespace(%s)\n", name); |
| 1263 | #endif |
| 1264 | ns = xmlSearchNs(ctxt->myDoc, ctxt->node, name); |
| 1265 | if (ns == NULL) { /* ctxt->node may not have a parent yet ! */ |
| 1266 | if (ctxt->nodeNr >= 2) { |
| 1267 | parent = ctxt->nodeTab[ctxt->nodeNr - 2]; |
| 1268 | if (parent != NULL) |
| 1269 | ns = xmlSearchNs(ctxt->myDoc, parent, name); |
| 1270 | } |
| 1271 | } |
| 1272 | xmlSetNs(ctxt->node, ns); |
| 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * getNamespace: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1277 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1278 | * |
| 1279 | * Get the current element namespace. |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 1280 | * |
| 1281 | * Returns the xmlNsPtr or NULL if none |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1282 | */ |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 1283 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1284 | xmlNsPtr |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1285 | getNamespace(void *ctx) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1286 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1287 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1288 | xmlNsPtr ret; |
| 1289 | |
| 1290 | #ifdef DEBUG_SAX |
| 1291 | fprintf(stderr, "SAX.getNamespace()\n"); |
| 1292 | #endif |
| 1293 | ret = ctxt->node->ns; |
| 1294 | return(ret); |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * checkNamespace: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1299 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1300 | * @namespace: the namespace to check against |
| 1301 | * |
| 1302 | * Check that the current element namespace is the same as the |
| 1303 | * one read upon parsing. |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 1304 | * |
| 1305 | * Returns 1 if true 0 otherwise |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1306 | */ |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 1307 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1308 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1309 | checkNamespace(void *ctx, xmlChar *namespace) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1310 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1311 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1312 | xmlNodePtr cur = ctxt->node; |
| 1313 | |
| 1314 | #ifdef DEBUG_SAX |
| 1315 | fprintf(stderr, "SAX.checkNamespace(%s)\n", namespace); |
| 1316 | #endif |
| 1317 | |
| 1318 | /* |
| 1319 | * Check that the Name in the ETag is the same as in the STag. |
| 1320 | */ |
| 1321 | if (namespace == NULL) { |
| 1322 | if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
| 1323 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1324 | ctxt->sax->error(ctxt, |
| 1325 | "End tags for %s don't hold the namespace %s\n", |
| 1326 | cur->name, cur->ns->prefix); |
| 1327 | ctxt->wellFormed = 0; |
| 1328 | } |
| 1329 | } else { |
| 1330 | if ((cur->ns == NULL) || (cur->ns->prefix == NULL)) { |
| 1331 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1332 | ctxt->sax->error(ctxt, |
| 1333 | "End tags %s holds a prefix %s not used by the open tag\n", |
| 1334 | cur->name, namespace); |
| 1335 | ctxt->wellFormed = 0; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1336 | } else if (xmlStrcmp(namespace, cur->ns->prefix)) { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1337 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1338 | ctxt->sax->error(ctxt, |
| 1339 | "Start and End tags for %s don't use the same namespaces: %s and %s\n", |
| 1340 | cur->name, cur->ns->prefix, namespace); |
| 1341 | ctxt->wellFormed = 0; |
| 1342 | } else |
| 1343 | return(1); |
| 1344 | } |
| 1345 | return(0); |
| 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * namespaceDecl: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1350 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1351 | * @href: the namespace associated URN |
| 1352 | * @prefix: the namespace prefix |
| 1353 | * |
| 1354 | * A namespace has been parsed. |
| 1355 | */ |
| 1356 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1357 | namespaceDecl(void *ctx, const xmlChar *href, const xmlChar *prefix) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1358 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1359 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1360 | #ifdef DEBUG_SAX |
| 1361 | if (prefix == NULL) |
| 1362 | fprintf(stderr, "SAX.namespaceDecl(%s, NULL)\n", href); |
| 1363 | else |
| 1364 | fprintf(stderr, "SAX.namespaceDecl(%s, %s)\n", href, prefix); |
| 1365 | #endif |
| 1366 | xmlNewNs(ctxt->node, href, prefix); |
| 1367 | } |
| 1368 | |
| 1369 | /** |
| 1370 | * comment: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1371 | * @ctx: the user data (XML parser context) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1372 | * @value: the comment content |
| 1373 | * |
| 1374 | * A comment has been parsed. |
| 1375 | */ |
| 1376 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1377 | comment(void *ctx, const xmlChar *value) |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1378 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1379 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 1380 | xmlNodePtr ret; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1381 | xmlNodePtr parent = ctxt->node; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 1382 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1383 | #ifdef DEBUG_SAX |
| 1384 | fprintf(stderr, "SAX.comment(%s)\n", value); |
| 1385 | #endif |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 1386 | ret = xmlNewDocComment(ctxt->myDoc, value); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1387 | if (ret == NULL) return; |
| 1388 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1389 | if (ctxt->inSubset == 1) { |
| 1390 | xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret); |
| 1391 | return; |
| 1392 | } else if (ctxt->inSubset == 2) { |
| 1393 | xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret); |
| 1394 | return; |
| 1395 | } |
| 1396 | if ((ctxt->myDoc->children == NULL) || (parent == NULL)) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1397 | #ifdef DEBUG_SAX_TREE |
| 1398 | fprintf(stderr, "Setting comment as root\n"); |
| 1399 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1400 | xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret); |
| 1401 | return; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1402 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1403 | if (parent->type == XML_ELEMENT_NODE) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1404 | #ifdef DEBUG_SAX_TREE |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1405 | fprintf(stderr, "adding comment child to %s\n", parent->name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1406 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1407 | xmlAddChild(parent, ret); |
| 1408 | } else { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1409 | #ifdef DEBUG_SAX_TREE |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1410 | fprintf(stderr, "adding comment sibling to "); |
| 1411 | xmlDebugDumpOneNode(stderr, parent, 0); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1412 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1413 | xmlAddSibling(parent, ret); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1414 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * cdataBlock: |
| 1419 | * @ctx: the user data (XML parser context) |
| 1420 | * @value: The pcdata content |
| 1421 | * @len: the block length |
| 1422 | * |
| 1423 | * called when a pcdata block has been parsed |
| 1424 | */ |
| 1425 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1426 | cdataBlock(void *ctx, const xmlChar *value, int len) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1427 | { |
| 1428 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 1429 | xmlNodePtr ret, lastChild; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1430 | |
| 1431 | #ifdef DEBUG_SAX |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1432 | fprintf(stderr, "SAX.pcdata(%.10s, %d)\n", value, len); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1433 | #endif |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 1434 | lastChild = xmlGetLastChild(ctxt->node); |
| 1435 | #ifdef DEBUG_SAX_TREE |
| 1436 | fprintf(stderr, "add chars to %s \n", ctxt->node->name); |
| 1437 | #endif |
| 1438 | if ((lastChild != NULL) && |
| 1439 | (lastChild->type == XML_CDATA_SECTION_NODE)) { |
| 1440 | xmlTextConcat(lastChild, value, len); |
| 1441 | } else { |
| 1442 | ret = xmlNewCDataBlock(ctxt->myDoc, value, len); |
| 1443 | xmlAddChild(ctxt->node, ret); |
| 1444 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1447 | /* |
| 1448 | * Default handler for XML, builds the DOM tree |
| 1449 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1450 | xmlSAXHandler xmlDefaultSAXHandler = { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1451 | internalSubset, |
| 1452 | isStandalone, |
| 1453 | hasInternalSubset, |
| 1454 | hasExternalSubset, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1455 | resolveEntity, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1456 | getEntity, |
| 1457 | entityDecl, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1458 | notationDecl, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1459 | attributeDecl, |
| 1460 | elementDecl, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1461 | unparsedEntityDecl, |
| 1462 | setDocumentLocator, |
| 1463 | startDocument, |
| 1464 | endDocument, |
| 1465 | startElement, |
| 1466 | endElement, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1467 | reference, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1468 | characters, |
| 1469 | ignorableWhitespace, |
| 1470 | processingInstruction, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1471 | comment, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1472 | xmlParserWarning, |
| 1473 | xmlParserError, |
| 1474 | xmlParserError, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1475 | getParameterEntity, |
| 1476 | cdataBlock, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1477 | externalSubset, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1478 | }; |
| 1479 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1480 | /** |
| 1481 | * xmlDefaultSAXHandlerInit: |
| 1482 | * |
| 1483 | * Initialize the default SAX handler |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1484 | */ |
| 1485 | void |
| 1486 | xmlDefaultSAXHandlerInit(void) |
| 1487 | { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1488 | xmlDefaultSAXHandler.internalSubset = internalSubset; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1489 | xmlDefaultSAXHandler.externalSubset = externalSubset; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1490 | xmlDefaultSAXHandler.isStandalone = isStandalone; |
| 1491 | xmlDefaultSAXHandler.hasInternalSubset = hasInternalSubset; |
| 1492 | xmlDefaultSAXHandler.hasExternalSubset = hasExternalSubset; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1493 | xmlDefaultSAXHandler.resolveEntity = resolveEntity; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1494 | xmlDefaultSAXHandler.getEntity = getEntity; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1495 | xmlDefaultSAXHandler.getParameterEntity = getParameterEntity; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1496 | xmlDefaultSAXHandler.entityDecl = entityDecl; |
| 1497 | xmlDefaultSAXHandler.attributeDecl = attributeDecl; |
| 1498 | xmlDefaultSAXHandler.elementDecl = elementDecl; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1499 | xmlDefaultSAXHandler.notationDecl = notationDecl; |
| 1500 | xmlDefaultSAXHandler.unparsedEntityDecl = unparsedEntityDecl; |
| 1501 | xmlDefaultSAXHandler.setDocumentLocator = setDocumentLocator; |
| 1502 | xmlDefaultSAXHandler.startDocument = startDocument; |
| 1503 | xmlDefaultSAXHandler.endDocument = endDocument; |
| 1504 | xmlDefaultSAXHandler.startElement = startElement; |
| 1505 | xmlDefaultSAXHandler.endElement = endElement; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1506 | xmlDefaultSAXHandler.reference = reference; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1507 | xmlDefaultSAXHandler.characters = characters; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1508 | xmlDefaultSAXHandler.cdataBlock = cdataBlock; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1509 | xmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace; |
| 1510 | xmlDefaultSAXHandler.processingInstruction = processingInstruction; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 1511 | xmlDefaultSAXHandler.comment = comment; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1512 | if (xmlGetWarningsDefaultValue == 0) |
| 1513 | xmlDefaultSAXHandler.warning = NULL; |
| 1514 | else |
| 1515 | xmlDefaultSAXHandler.warning = xmlParserWarning; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1516 | xmlDefaultSAXHandler.error = xmlParserError; |
| 1517 | xmlDefaultSAXHandler.fatalError = xmlParserError; |
| 1518 | } |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1519 | |
| 1520 | /* |
| 1521 | * Default handler for HTML, builds the DOM tree |
| 1522 | */ |
| 1523 | xmlSAXHandler htmlDefaultSAXHandler = { |
Daniel Veillard | d83eb82 | 2000-06-30 18:39:56 +0000 | [diff] [blame] | 1524 | internalSubset, |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1525 | NULL, |
| 1526 | NULL, |
| 1527 | NULL, |
| 1528 | NULL, |
| 1529 | getEntity, |
| 1530 | NULL, |
| 1531 | NULL, |
| 1532 | NULL, |
| 1533 | NULL, |
| 1534 | NULL, |
| 1535 | setDocumentLocator, |
| 1536 | startDocument, |
| 1537 | endDocument, |
| 1538 | startElement, |
| 1539 | endElement, |
| 1540 | NULL, |
| 1541 | characters, |
| 1542 | ignorableWhitespace, |
| 1543 | NULL, |
| 1544 | comment, |
| 1545 | xmlParserWarning, |
| 1546 | xmlParserError, |
| 1547 | xmlParserError, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1548 | getParameterEntity, |
| 1549 | NULL, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1550 | NULL, |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1551 | }; |
| 1552 | |
| 1553 | /** |
| 1554 | * htmlDefaultSAXHandlerInit: |
| 1555 | * |
| 1556 | * Initialize the default SAX handler |
| 1557 | */ |
| 1558 | void |
| 1559 | htmlDefaultSAXHandlerInit(void) |
| 1560 | { |
Daniel Veillard | d83eb82 | 2000-06-30 18:39:56 +0000 | [diff] [blame] | 1561 | htmlDefaultSAXHandler.internalSubset = internalSubset; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1562 | htmlDefaultSAXHandler.externalSubset = NULL; |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1563 | htmlDefaultSAXHandler.isStandalone = NULL; |
| 1564 | htmlDefaultSAXHandler.hasInternalSubset = NULL; |
| 1565 | htmlDefaultSAXHandler.hasExternalSubset = NULL; |
| 1566 | htmlDefaultSAXHandler.resolveEntity = NULL; |
| 1567 | htmlDefaultSAXHandler.getEntity = getEntity; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1568 | htmlDefaultSAXHandler.getParameterEntity = NULL; |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1569 | htmlDefaultSAXHandler.entityDecl = NULL; |
| 1570 | htmlDefaultSAXHandler.attributeDecl = NULL; |
| 1571 | htmlDefaultSAXHandler.elementDecl = NULL; |
| 1572 | htmlDefaultSAXHandler.notationDecl = NULL; |
| 1573 | htmlDefaultSAXHandler.unparsedEntityDecl = NULL; |
| 1574 | htmlDefaultSAXHandler.setDocumentLocator = setDocumentLocator; |
| 1575 | htmlDefaultSAXHandler.startDocument = startDocument; |
| 1576 | htmlDefaultSAXHandler.endDocument = endDocument; |
| 1577 | htmlDefaultSAXHandler.startElement = startElement; |
| 1578 | htmlDefaultSAXHandler.endElement = endElement; |
| 1579 | htmlDefaultSAXHandler.reference = NULL; |
| 1580 | htmlDefaultSAXHandler.characters = characters; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1581 | htmlDefaultSAXHandler.cdataBlock = NULL; |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1582 | htmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace; |
| 1583 | htmlDefaultSAXHandler.processingInstruction = NULL; |
| 1584 | htmlDefaultSAXHandler.comment = comment; |
| 1585 | htmlDefaultSAXHandler.warning = xmlParserWarning; |
| 1586 | htmlDefaultSAXHandler.error = xmlParserError; |
| 1587 | htmlDefaultSAXHandler.fatalError = xmlParserError; |
| 1588 | } |