summaryrefslogtreecommitdiff
path: root/SAX2.c
diff options
context:
space:
mode:
Diffstat (limited to 'SAX2.c')
-rw-r--r--SAX2.c67
1 files changed, 56 insertions, 11 deletions
diff --git a/SAX2.c b/SAX2.c
index c0482c0..126a79f 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -1756,7 +1756,6 @@ void
xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
- xmlParserNodeInfo node_info;
xmlNodePtr cur;
if (ctx == NULL) return;
@@ -1770,10 +1769,10 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
/* Capture end position and add node */
if (cur != NULL && ctxt->record_info) {
- node_info.end_pos = ctxt->input->cur - ctxt->input->base;
- node_info.end_line = ctxt->input->line;
- node_info.node = cur;
- xmlParserAddNodeInfo(ctxt, &node_info);
+ ctxt->nodeInfo->end_pos = ctxt->input->cur - ctxt->input->base;
+ ctxt->nodeInfo->end_line = ctxt->input->line;
+ ctxt->nodeInfo->node = cur;
+ xmlParserAddNodeInfo(ctxt, ctxt->nodeInfo);
}
ctxt->nodemem = -1;
@@ -2163,6 +2162,7 @@ xmlSAX2StartElementNs(void *ctx,
xmlNodePtr parent;
xmlNsPtr last = NULL, ns;
const xmlChar *uri, *pref;
+ xmlChar *lname = NULL;
int i, j;
if (ctx == NULL) return;
@@ -2182,6 +2182,20 @@ xmlSAX2StartElementNs(void *ctx,
}
/*
+ * Take care of the rare case of an undefined namespace prefix
+ */
+ if ((prefix != NULL) && (URI == NULL)) {
+ if (ctxt->dictNames) {
+ const xmlChar *fullname;
+
+ fullname = xmlDictQLookup(ctxt->dict, prefix, localname);
+ if (fullname != NULL)
+ localname = fullname;
+ } else {
+ lname = xmlBuildQName(localname, prefix, NULL, 0);
+ }
+ }
+ /*
* allocate the node
*/
if (ctxt->freeElems != NULL) {
@@ -2194,7 +2208,10 @@ xmlSAX2StartElementNs(void *ctx,
if (ctxt->dictNames)
ret->name = localname;
else {
- ret->name = xmlStrdup(localname);
+ if (lname == NULL)
+ ret->name = xmlStrdup(localname);
+ else
+ ret->name = lname;
if (ret->name == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
@@ -2206,8 +2223,11 @@ xmlSAX2StartElementNs(void *ctx,
if (ctxt->dictNames)
ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
(xmlChar *) localname, NULL);
- else
+ else if (lname == NULL)
ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
+ else
+ ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
+ (xmlChar *) lname, NULL);
if (ret == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
@@ -2222,7 +2242,7 @@ xmlSAX2StartElementNs(void *ctx,
}
}
- if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
+ if (parent == NULL) {
xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
}
/*
@@ -2314,8 +2334,33 @@ xmlSAX2StartElementNs(void *ctx,
*/
if (nb_attributes > 0) {
for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {
+ /*
+ * Handle the rare case of an undefined atribute prefix
+ */
+ if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) {
+ if (ctxt->dictNames) {
+ const xmlChar *fullname;
+
+ fullname = xmlDictQLookup(ctxt->dict, attributes[j+1],
+ attributes[j]);
+ if (fullname != NULL) {
+ xmlSAX2AttributeNs(ctxt, fullname, NULL,
+ attributes[j+3], attributes[j+4]);
+ continue;
+ }
+ } else {
+ lname = xmlBuildQName(attributes[j], attributes[j+1],
+ NULL, 0);
+ if (lname != NULL) {
+ xmlSAX2AttributeNs(ctxt, lname, NULL,
+ attributes[j+3], attributes[j+4]);
+ xmlFree(lname);
+ continue;
+ }
+ }
+ }
xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],
- attributes[j+3], attributes[j+4]);
+ attributes[j+3], attributes[j+4]);
}
}
@@ -2595,7 +2640,7 @@ xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
return;
}
- if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
+ if (parent == NULL) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"Setting PI %s as root\n", target);
@@ -2656,7 +2701,7 @@ xmlSAX2Comment(void *ctx, const xmlChar *value)
xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
return;
}
- if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
+ if (parent == NULL) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"Setting xmlSAX2Comment as root\n");