XML C parser available under the MIT license. http://xmlsoft.org/

Dependents:   libiio

Committer:
pcercuei
Date:
Thu Aug 25 10:07:34 2016 +0000
Revision:
1:26f20484cbdc
Parent:
0:03b5121a232e
Add config.h and dummy.c containing empty functions

Who changed what in which revision?

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