updated to more recent libxml2 version (work in progress)
This commit is contained in:
@@ -83,15 +83,126 @@ xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error,
|
||||
ctxt->errNo = error;
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
|
||||
schannel = ctxt->sax->serror;
|
||||
}
|
||||
__xmlRaiseError(schannel,
|
||||
ctxt->vctxt.error, ctxt->vctxt.userData,
|
||||
ctxt, NULL, XML_FROM_DTD, error,
|
||||
XML_ERR_ERROR, NULL, 0, (const char *) str1,
|
||||
(const char *) str2, NULL, 0, 0,
|
||||
msg, (const char *) str1, (const char *) str2);
|
||||
if (ctxt != NULL)
|
||||
__xmlRaiseError(schannel,
|
||||
ctxt->vctxt.error, ctxt->vctxt.userData,
|
||||
ctxt, NULL, XML_FROM_DTD, error,
|
||||
XML_ERR_ERROR, NULL, 0, (const char *) str1,
|
||||
(const char *) str2, NULL, 0, 0,
|
||||
msg, (const char *) str1, (const char *) str2);
|
||||
ctxt->valid = 0;
|
||||
} else {
|
||||
__xmlRaiseError(schannel,
|
||||
NULL, NULL,
|
||||
ctxt, NULL, XML_FROM_DTD, error,
|
||||
XML_ERR_ERROR, NULL, 0, (const char *) str1,
|
||||
(const char *) str2, NULL, 0, 0,
|
||||
msg, (const char *) str1, (const char *) str2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlFatalErrMsg:
|
||||
* @ctxt: an XML parser context
|
||||
* @error: the error number
|
||||
* @msg: the error message
|
||||
* @str1: an error string
|
||||
* @str2: an error string
|
||||
*
|
||||
* Handle a fatal parser error, i.e. violating Well-Formedness constraints
|
||||
*/
|
||||
static void
|
||||
xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
|
||||
const char *msg, const xmlChar *str1, const xmlChar *str2)
|
||||
{
|
||||
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
|
||||
(ctxt->instate == XML_PARSER_EOF))
|
||||
return;
|
||||
if (ctxt != NULL)
|
||||
ctxt->errNo = error;
|
||||
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
|
||||
XML_ERR_FATAL, NULL, 0,
|
||||
(const char *) str1, (const char *) str2,
|
||||
NULL, 0, 0, msg, str1, str2);
|
||||
if (ctxt != NULL) {
|
||||
ctxt->wellFormed = 0;
|
||||
ctxt->valid = 0;
|
||||
if (ctxt->recovery == 0)
|
||||
ctxt->disableSAX = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlWarnMsg:
|
||||
* @ctxt: an XML parser context
|
||||
* @error: the error number
|
||||
* @msg: the error message
|
||||
* @str1: an error string
|
||||
* @str2: an error string
|
||||
*
|
||||
* Handle a parser warning
|
||||
*/
|
||||
static void
|
||||
xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
|
||||
const char *msg, const xmlChar *str1)
|
||||
{
|
||||
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
|
||||
(ctxt->instate == XML_PARSER_EOF))
|
||||
return;
|
||||
if (ctxt != NULL)
|
||||
ctxt->errNo = error;
|
||||
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
|
||||
XML_ERR_WARNING, NULL, 0,
|
||||
(const char *) str1, NULL,
|
||||
NULL, 0, 0, msg, str1);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlNsErrMsg:
|
||||
* @ctxt: an XML parser context
|
||||
* @error: the error number
|
||||
* @msg: the error message
|
||||
* @str1: an error string
|
||||
* @str2: an error string
|
||||
*
|
||||
* Handle a namespace error
|
||||
*/
|
||||
static void
|
||||
xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
|
||||
const char *msg, const xmlChar *str1, const xmlChar *str2)
|
||||
{
|
||||
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
|
||||
(ctxt->instate == XML_PARSER_EOF))
|
||||
return;
|
||||
if (ctxt != NULL)
|
||||
ctxt->errNo = error;
|
||||
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
|
||||
XML_ERR_ERROR, NULL, 0,
|
||||
(const char *) str1, (const char *) str2,
|
||||
NULL, 0, 0, msg, str1, str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlNsWarnMsg:
|
||||
* @ctxt: an XML parser context
|
||||
* @error: the error number
|
||||
* @msg: the error message
|
||||
* @str1: an error string
|
||||
*
|
||||
* Handle a namespace warning
|
||||
*/
|
||||
static void
|
||||
xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
|
||||
const char *msg, const xmlChar *str1, const xmlChar *str2)
|
||||
{
|
||||
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
|
||||
(ctxt->instate == XML_PARSER_EOF))
|
||||
return;
|
||||
if (ctxt != NULL)
|
||||
ctxt->errNo = error;
|
||||
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
|
||||
XML_ERR_WARNING, NULL, 0,
|
||||
(const char *) str1, (const char *) str2,
|
||||
NULL, 0, 0, msg, str1, str2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +233,7 @@ const xmlChar *
|
||||
xmlSAX2GetSystemId(void *ctx)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
|
||||
if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL);
|
||||
return((const xmlChar *) ctxt->input->filename);
|
||||
}
|
||||
|
||||
@@ -134,12 +245,12 @@ xmlSAX2GetSystemId(void *ctx)
|
||||
*
|
||||
* Returns an int
|
||||
*/
|
||||
intptr_t
|
||||
int
|
||||
xmlSAX2GetLineNumber(void *ctx)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
|
||||
return (intptr_t) (ctxt->input->line);
|
||||
return(ctxt->input->line);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,12 +261,12 @@ xmlSAX2GetLineNumber(void *ctx)
|
||||
*
|
||||
* Returns an int
|
||||
*/
|
||||
intptr_t
|
||||
int
|
||||
xmlSAX2GetColumnNumber(void *ctx)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
|
||||
return ctxt->input->col;
|
||||
return(ctxt->input->col);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,12 +547,9 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name)
|
||||
ctxt->myDoc->standalone = 0;
|
||||
ret = xmlGetDocEntity(ctxt->myDoc, name);
|
||||
if (ret != NULL) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"Entity(%s) document marked standalone but requires external subset\n",
|
||||
name);
|
||||
ctxt->valid = 0;
|
||||
ctxt->wellFormed = 0;
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE,
|
||||
"Entity(%s) document marked standalone but requires external subset\n",
|
||||
name, NULL);
|
||||
}
|
||||
ctxt->myDoc->standalone = 1;
|
||||
}
|
||||
@@ -466,11 +574,8 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name)
|
||||
if (val == 0) {
|
||||
xmlAddChildList((xmlNodePtr) ret, children);
|
||||
} else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"Failure to process entity %s\n", name);
|
||||
ctxt->wellFormed = 0;
|
||||
ctxt->valid = 0;
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
|
||||
"Failure to process entity %s\n", name, NULL);
|
||||
ctxt->validate = 0;
|
||||
return(NULL);
|
||||
}
|
||||
@@ -532,10 +637,10 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
|
||||
if (ctxt->inSubset == 1) {
|
||||
ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId,
|
||||
systemId, content);
|
||||
if ((ent == NULL) && (ctxt->pedantic) &&
|
||||
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
|
||||
ctxt->sax->warning(ctxt->userData,
|
||||
"Entity(%s) already defined in the internal subset\n", name);
|
||||
if ((ent == NULL) && (ctxt->pedantic))
|
||||
xmlWarnMsg(ctxt, XML_WAR_ENTITY_REDEFINED,
|
||||
"Entity(%s) already defined in the internal subset\n",
|
||||
name);
|
||||
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
|
||||
xmlChar *URI;
|
||||
const char *base = NULL;
|
||||
@@ -568,9 +673,9 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
|
||||
ent->URI = URI;
|
||||
}
|
||||
} else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"SAX.xmlSAX2EntityDecl(%s) called while not in subset\n", name);
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
|
||||
"SAX.xmlSAX2EntityDecl(%s) called while not in subset\n",
|
||||
name, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,7 +700,9 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
|
||||
xmlAttributePtr attr;
|
||||
xmlChar *name = NULL, *prefix = NULL;
|
||||
|
||||
if (ctx == NULL) return;
|
||||
if ((ctxt == NULL) || (ctxt->myDoc == NULL))
|
||||
return;
|
||||
|
||||
#ifdef DEBUG_SAX
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n",
|
||||
@@ -623,9 +730,9 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
|
||||
name, prefix, (xmlAttributeType) type,
|
||||
(xmlAttributeDefault) def, defaultValue, tree);
|
||||
else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n", name);
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
|
||||
"SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n",
|
||||
name, NULL);
|
||||
xmlFreeEnumeration(tree);
|
||||
return;
|
||||
}
|
||||
@@ -633,7 +740,7 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
|
||||
if (ctxt->vctxt.valid == 0)
|
||||
ctxt->valid = 0;
|
||||
if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) &&
|
||||
(ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset != NULL))
|
||||
(ctxt->myDoc->intSubset != NULL))
|
||||
ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
|
||||
attr);
|
||||
#endif /* LIBXML_VALID_ENABLED */
|
||||
@@ -659,7 +766,9 @@ xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type,
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlElementPtr elem = NULL;
|
||||
|
||||
if (ctx == NULL) return;
|
||||
if ((ctxt == NULL) || (ctxt->myDoc == NULL))
|
||||
return;
|
||||
|
||||
#ifdef DEBUG_SAX
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type);
|
||||
@@ -672,10 +781,9 @@ xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type,
|
||||
elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
|
||||
name, (xmlElementTypeVal) type, content);
|
||||
else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",
|
||||
name);
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
|
||||
"SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",
|
||||
name, NULL);
|
||||
return;
|
||||
}
|
||||
#ifdef LIBXML_VALID_ENABLED
|
||||
@@ -704,18 +812,18 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name,
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlNotationPtr nota = NULL;
|
||||
|
||||
if (ctx == NULL) return;
|
||||
if ((ctxt == NULL) || (ctxt->myDoc == NULL))
|
||||
return;
|
||||
|
||||
#ifdef DEBUG_SAX
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId);
|
||||
#endif
|
||||
|
||||
if ((publicId == NULL) && (systemId == NULL)) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n", name);
|
||||
ctxt->valid = 0;
|
||||
ctxt->wellFormed = 0;
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
|
||||
"SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n",
|
||||
name, NULL);
|
||||
return;
|
||||
} else if (ctxt->inSubset == 1)
|
||||
nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
|
||||
@@ -724,15 +832,15 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name,
|
||||
nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
|
||||
publicId, systemId);
|
||||
else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"SAX.xmlSAX2NotationDecl(%s) called while not in subset\n", name);
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
|
||||
"SAX.xmlSAX2NotationDecl(%s) called while not in subset\n",
|
||||
name, NULL);
|
||||
return;
|
||||
}
|
||||
#ifdef LIBXML_VALID_ENABLED
|
||||
if (nota == NULL) ctxt->valid = 0;
|
||||
if (ctxt->validate && ctxt->wellFormed &&
|
||||
ctxt->myDoc && ctxt->myDoc->intSubset)
|
||||
if ((ctxt->validate) && (ctxt->wellFormed) &&
|
||||
(ctxt->myDoc->intSubset != NULL))
|
||||
ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
|
||||
nota);
|
||||
#endif /* LIBXML_VALID_ENABLED */
|
||||
@@ -802,9 +910,9 @@ xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name,
|
||||
ent->URI = URI;
|
||||
}
|
||||
} else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n", name);
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
|
||||
"SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n",
|
||||
name, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -926,7 +1034,7 @@ xmlSAX2EndDocument(void *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED)
|
||||
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED)
|
||||
/**
|
||||
* xmlSAX2AttributeInternal:
|
||||
* @ctx: the user data (XML parser context)
|
||||
@@ -956,13 +1064,13 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
|
||||
name = xmlSplitQName(ctxt, fullname, &ns);
|
||||
if ((name != NULL) && (name[0] == 0)) {
|
||||
if (xmlStrEqual(ns, BAD_CAST "xmlns")) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"invalid namespace declaration '%s'\n", fullname);
|
||||
xmlNsErrMsg(ctxt, XML_ERR_NS_DECL_ERROR,
|
||||
"invalid namespace declaration '%s'\n",
|
||||
fullname, NULL);
|
||||
} else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
|
||||
ctxt->sax->warning(ctxt->userData,
|
||||
"Avoid attribute ending with ':' like '%s'\n", fullname);
|
||||
xmlNsWarnMsg(ctxt, XML_WAR_NS_COLUMN,
|
||||
"Avoid attribute ending with ':' like '%s'\n",
|
||||
fullname, NULL);
|
||||
}
|
||||
if (ns != NULL)
|
||||
xmlFree(ns);
|
||||
@@ -1076,22 +1184,19 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
|
||||
}
|
||||
|
||||
if (val[0] == 0) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
"Empty namespace name for prefix %s\n", name);
|
||||
xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY,
|
||||
"Empty namespace name for prefix %s\n", name, NULL);
|
||||
}
|
||||
if ((ctxt->pedantic != 0) && (val[0] != 0)) {
|
||||
xmlURIPtr uri;
|
||||
|
||||
uri = xmlParseURI((const char *)val);
|
||||
if (uri == NULL) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
|
||||
ctxt->sax->warning(ctxt->userData,
|
||||
xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
|
||||
"xmlns:%s: %s not a valid URI\n", name, value);
|
||||
} else {
|
||||
if (uri->scheme == NULL) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
|
||||
ctxt->sax->warning(ctxt->userData,
|
||||
xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
|
||||
"xmlns:%s: URI %s is not absolute\n", name, value);
|
||||
}
|
||||
xmlFreeURI(uri);
|
||||
@@ -1124,8 +1229,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
|
||||
xmlAttrPtr prop;
|
||||
namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
|
||||
if (namespace == NULL) {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
|
||||
"Namespace prefix %s of attribute %s is not defined\n",
|
||||
ns, name);
|
||||
}
|
||||
@@ -1136,9 +1240,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
|
||||
if ((xmlStrEqual(name, prop->name)) &&
|
||||
((namespace == prop->ns) ||
|
||||
(xmlStrEqual(namespace->href, prop->ns->href)))) {
|
||||
ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt->userData,
|
||||
xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED,
|
||||
"Attribute %s in %s redefined\n",
|
||||
name, namespace->href);
|
||||
ctxt->wellFormed = 0;
|
||||
@@ -1226,11 +1328,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
|
||||
* when validating, the ID registration is done at the attribute
|
||||
* validation level. Otherwise we have to do specific handling here.
|
||||
*/
|
||||
if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
|
||||
xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
|
||||
else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
|
||||
xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
|
||||
else if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {
|
||||
if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {
|
||||
/*
|
||||
* Add the xml:id value
|
||||
*
|
||||
@@ -1242,7 +1340,10 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
|
||||
(const char *) value, NULL);
|
||||
}
|
||||
xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
|
||||
}
|
||||
} else if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
|
||||
xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
|
||||
else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
|
||||
xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
|
||||
}
|
||||
|
||||
error:
|
||||
@@ -1669,7 +1770,7 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
|
||||
* Returns the newly allocated string or NULL if not needed or error
|
||||
*/
|
||||
static xmlNodePtr
|
||||
xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) {
|
||||
xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
|
||||
xmlNodePtr ret;
|
||||
const xmlChar *intern = NULL;
|
||||
|
||||
@@ -1687,6 +1788,7 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) {
|
||||
xmlErrMemory(ctxt, "xmlSAX2Characters");
|
||||
return(NULL);
|
||||
}
|
||||
memset(ret, 0, sizeof(xmlNode));
|
||||
/*
|
||||
* intern the formatting blanks found between tags, or the
|
||||
* very short strings
|
||||
@@ -1694,7 +1796,14 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) {
|
||||
if (ctxt->dictNames) {
|
||||
xmlChar cur = str[len];
|
||||
|
||||
if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
|
||||
if ((len < (int) (2 * sizeof(void *))) &&
|
||||
(ctxt->options & XML_PARSE_COMPACT)) {
|
||||
/* store the string in the node overrithing properties and nsDef */
|
||||
xmlChar *tmp = (xmlChar *) &(ret->properties);
|
||||
memcpy(tmp, str, len);
|
||||
tmp[len] = 0;
|
||||
intern = tmp;
|
||||
} else if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
|
||||
((cur == '<') && (str[len + 1] != '!')))) {
|
||||
intern = xmlDictLookup(ctxt->dict, str, len);
|
||||
} else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') &&
|
||||
@@ -1708,7 +1817,6 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) {
|
||||
}
|
||||
}
|
||||
skip:
|
||||
memset(ret, 0, sizeof(xmlNode));
|
||||
ret->type = XML_TEXT_NODE;
|
||||
|
||||
ret->name = xmlStringText;
|
||||
@@ -1950,16 +2058,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
|
||||
* when validating, the ID registration is done at the attribute
|
||||
* validation level. Otherwise we have to do specific handling here.
|
||||
*/
|
||||
if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) {
|
||||
/* might be worth duplicate entry points and not copy */
|
||||
if (dup == NULL)
|
||||
dup = xmlStrndup(value, valueend - value);
|
||||
xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
|
||||
} else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) {
|
||||
if (dup == NULL)
|
||||
dup = xmlStrndup(value, valueend - value);
|
||||
xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret);
|
||||
} else if ((prefix == ctxt->str_xml) &&
|
||||
if ((prefix == ctxt->str_xml) &&
|
||||
(localname[0] == 'i') && (localname[1] == 'd') &&
|
||||
(localname[2] == 0)) {
|
||||
/*
|
||||
@@ -1977,6 +2076,15 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
|
||||
}
|
||||
#endif
|
||||
xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
|
||||
} else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) {
|
||||
/* might be worth duplicate entry points and not copy */
|
||||
if (dup == NULL)
|
||||
dup = xmlStrndup(value, valueend - value);
|
||||
xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
|
||||
} else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) {
|
||||
if (dup == NULL)
|
||||
dup = xmlStrndup(value, valueend - value);
|
||||
xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret);
|
||||
}
|
||||
}
|
||||
if (dup != NULL)
|
||||
@@ -2007,8 +2115,8 @@ xmlSAX2StartElementNs(void *ctx,
|
||||
const xmlChar *URI,
|
||||
int nb_namespaces,
|
||||
const xmlChar **namespaces,
|
||||
intptr_t nb_attributes,
|
||||
intptr_t nb_defaulted,
|
||||
int nb_attributes,
|
||||
int nb_defaulted,
|
||||
const xmlChar **attributes)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
@@ -2016,7 +2124,7 @@ xmlSAX2StartElementNs(void *ctx,
|
||||
xmlNodePtr parent;
|
||||
xmlNsPtr last = NULL, ns;
|
||||
const xmlChar *uri, *pref;
|
||||
intptr_t i, j;
|
||||
int i, j;
|
||||
|
||||
if (ctx == NULL) return;
|
||||
parent = ctxt->node;
|
||||
@@ -2137,9 +2245,13 @@ xmlSAX2StartElementNs(void *ctx,
|
||||
*/
|
||||
if ((URI != NULL) && (ret->ns == NULL)) {
|
||||
ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
|
||||
if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
|
||||
ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
|
||||
}
|
||||
if (ret->ns == NULL) {
|
||||
ns = xmlNewNs(ret, NULL, prefix);
|
||||
if (ns == NULL) {
|
||||
|
||||
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
|
||||
return;
|
||||
}
|
||||
@@ -2259,7 +2371,7 @@ xmlSAX2Reference(void *ctx, const xmlChar *name)
|
||||
* receiving some chars from the parser.
|
||||
*/
|
||||
void
|
||||
xmlSAX2Characters(void *ctx, const xmlChar *ch, intptr_t len)
|
||||
xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlNodePtr lastChild;
|
||||
@@ -2317,17 +2429,20 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, intptr_t len)
|
||||
* We try to minimaze realloc() uses and avoid copying
|
||||
* and recomputing length over and over.
|
||||
*/
|
||||
if ((ctxt->nodemem == ctxt->nodelen + 1) &&
|
||||
(xmlDictOwns(ctxt->dict, lastChild->content))) {
|
||||
if (lastChild->content == (xmlChar *)&(lastChild->properties)) {
|
||||
lastChild->content = xmlStrdup(lastChild->content);
|
||||
lastChild->properties = NULL;
|
||||
} else if ((ctxt->nodemem == ctxt->nodelen + 1) &&
|
||||
(xmlDictOwns(ctxt->dict, lastChild->content))) {
|
||||
lastChild->content = xmlStrdup(lastChild->content);
|
||||
}
|
||||
if (ctxt->nodelen + len >= ctxt->nodemem) {
|
||||
xmlChar *newbuf;
|
||||
size_t size;
|
||||
int size;
|
||||
|
||||
size = ctxt->nodemem + len;
|
||||
size *= 2;
|
||||
newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
|
||||
newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
|
||||
if (newbuf == NULL) {
|
||||
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
|
||||
return;
|
||||
@@ -2370,7 +2485,7 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, intptr_t len)
|
||||
* UNUSED: by default the DOM building will use xmlSAX2Characters
|
||||
*/
|
||||
void
|
||||
xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, intptr_t len ATTRIBUTE_UNUSED)
|
||||
xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
|
||||
#ifdef DEBUG_SAX
|
||||
@@ -2406,6 +2521,14 @@ xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
|
||||
if (ret == NULL) return;
|
||||
parent = ctxt->node;
|
||||
|
||||
if (ctxt->linenumbers) {
|
||||
if (ctxt->input != NULL) {
|
||||
if (ctxt->input->line < 65535)
|
||||
ret->line = (short) ctxt->input->line;
|
||||
else
|
||||
ret->line = 65535;
|
||||
}
|
||||
}
|
||||
if (ctxt->inSubset == 1) {
|
||||
xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
|
||||
return;
|
||||
@@ -2458,6 +2581,14 @@ xmlSAX2Comment(void *ctx, const xmlChar *value)
|
||||
#endif
|
||||
ret = xmlNewDocComment(ctxt->myDoc, value);
|
||||
if (ret == NULL) return;
|
||||
if (ctxt->linenumbers) {
|
||||
if (ctxt->input != NULL) {
|
||||
if (ctxt->input->line < 65535)
|
||||
ret->line = (short) ctxt->input->line;
|
||||
else
|
||||
ret->line = 65535;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctxt->inSubset == 1) {
|
||||
xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
|
||||
@@ -2499,7 +2630,7 @@ xmlSAX2Comment(void *ctx, const xmlChar *value)
|
||||
* called when a pcdata block has been parsed
|
||||
*/
|
||||
void
|
||||
xmlSAX2CDataBlock(void *ctx, const xmlChar *value, intptr_t len)
|
||||
xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlNodePtr ret, lastChild;
|
||||
|
||||
Reference in New Issue
Block a user