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