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