diff --git a/expat/doc/reference.html b/expat/doc/reference.html index 59e43909..d848ab11 100644 --- a/expat/doc/reference.html +++ b/expat/doc/reference.html @@ -389,8 +389,8 @@ namespace declaration handlers with XML_SetNamespaceDeclHandler.

Element type and attribute names that belong to a given namespace are -passed to the appropriate handler in expanded form. This expanded form -is a concatenation of the namespace URI, the separator character (which +passed to the appropriate handler in expanded form. By default this expanded +form is a concatenation of the namespace URI, the separator character (which is the 2nd argument to XML_ParserCreateNS), and the local name (i.e. the part after the colon). Names with undeclared prefixes are passed through to the handlers unchanged, with the prefix and colon still @@ -398,6 +398,12 @@ attached. Unprefixed attribute names are never expanded, and unprefixed element names are only expanded when they are in the scope of a default namespace. +

However if XML_SetReturnNSTriplet +has been called with a non-zero do_nst parameter, then the +expanded form for names with an explicit prefix is a concatenation of: +URI, separator, local name, separator, prefix. +

+

You can set handlers for the start of a namespace declaration and for the end of a scope of a declaration with the XML_SetNamespaceDeclHandler function. @@ -1435,5 +1441,25 @@ The choices for code are: +

+void
+XML_SetReturnNSTriplet(XML_Parser parser,
+                       int        do_nst);
+
+
+

+This function only has an effect when using a parser created with +XML_ParserCreateNS, i.e. when namespace +processing is in effect. The do_nst sets whether or not prefixes +are returned with names qualified with a namespace prefix. If this function +is called with do_nst non-zero, then afterwards namespace +qualified names (that is qualified with a prefix as opposed to belonging +to a default namespace) are returned as a triplet with the three parts +separated by the namespace separator specified when the parser was created. +The order of returned parts is URI, local name, and prefix.

+

If do_nst is zero, then namespaces are reported in the +default manner, URI then local_name separated by the namespace separator.

+
+ diff --git a/expat/lib/expat.h b/expat/lib/expat.h index 612c6a72..49be3ee7 100644 --- a/expat/lib/expat.h +++ b/expat/lib/expat.h @@ -167,6 +167,7 @@ typedef void (*XML_StartElementHandler)(void *userData, typedef void (*XML_EndElementHandler)(void *userData, const XML_Char *name); + /* s is not 0 terminated. */ typedef void (*XML_CharacterDataHandler)(void *userData, const XML_Char *s, @@ -389,10 +390,10 @@ XML_SetElementHandler(XML_Parser parser, XML_EndElementHandler end); void -XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler); +XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler); void -XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler); +XML_SetEndElementHandler(XML_Parser, XML_EndElementHandler); void XML_SetCharacterDataHandler(XML_Parser parser, @@ -490,6 +491,20 @@ processing instruction or character data. It causes the corresponding markup to be passed to the default handler. */ void XML_DefaultCurrent(XML_Parser parser); +/* If do_nst is non-zero, and namespace processing is in effect, and + a name has a prefix (i.e. an explicit namespace qualifier) then + that name is returned as a triplet in a single + string separated by the separator character specified when the parser + was created: URI + sep + local_name + sep + prefix. + + If do_nst is zero, then namespace information is returned in the + default manner (URI + sep + local_name) whether or not the names + has a prefix. +*/ + +void +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); + /* This value is passed as the userData argument to callbacks. */ void XML_SetUserData(XML_Parser parser, void *userData); diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c index 340d0452..55f2e518 100644 --- a/expat/lib/xmlparse.c +++ b/expat/lib/xmlparse.c @@ -362,6 +362,7 @@ typedef struct { const ENCODING *m_internalEncoding; const XML_Char *m_protocolEncodingName; int m_ns; + int m_ns_triplets; void *m_unknownEncodingMem; void *m_unknownEncodingData; void *m_unknownEncodingHandlerData; @@ -447,6 +448,7 @@ typedef struct { #define unknownEncodingRelease (((Parser *)parser)->m_unknownEncodingRelease) #define protocolEncodingName (((Parser *)parser)->m_protocolEncodingName) #define ns (((Parser *)parser)->m_ns) +#define ns_triplets (((Parser *)parser)->m_ns_triplets) #define prologState (((Parser *)parser)->m_prologState) #define processor (((Parser *)parser)->m_processor) #define errorCode (((Parser *)parser)->m_errorCode) @@ -627,6 +629,7 @@ XML_ParserCreate_MM(const XML_Char *encodingName, paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; #endif ns = 0; + ns_triplets = 0; poolInit(&tempPool, &(((Parser *) parser)->m_mem)); poolInit(&temp2Pool, &(((Parser *) parser)->m_mem)); protocolEncodingName = encodingName ? poolCopyString(&tempPool, encodingName) : 0; @@ -695,6 +698,7 @@ XML_Parser XML_ExternalEntityParserCreate(XML_Parser oldParser, XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; ELEMENT_TYPE * oldDeclElementType = declElementType; + void *oldUserData = userData; void *oldHandlerArg = handlerArg; int oldDefaultExpandInternalEntities = defaultExpandInternalEntities; @@ -702,6 +706,7 @@ XML_Parser XML_ExternalEntityParserCreate(XML_Parser oldParser, #ifdef XML_DTD int oldParamEntityParsing = paramEntityParsing; #endif + int oldns_triplets = ns_triplets; if (ns) { XML_Char tmp[2]; @@ -746,6 +751,7 @@ XML_Parser XML_ExternalEntityParserCreate(XML_Parser oldParser, if (oldExternalEntityRefHandlerArg != oldParser) externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; defaultExpandInternalEntities = oldDefaultExpandInternalEntities; + ns_triplets = oldns_triplets; #ifdef XML_DTD paramEntityParsing = oldParamEntityParsing; if (context) { @@ -827,6 +833,11 @@ void XML_UseParserAsHandlerArg(XML_Parser parser) handlerArg = parser; } +void +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) { + ns_triplets = do_nst; +} + void XML_SetUserData(XML_Parser parser, void *p) { if (handlerArg == userData) @@ -1985,6 +1996,15 @@ static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc, if (!poolAppendChar(&tempPool, *s)) return XML_ERROR_NO_MEMORY; } while (*s++); + if (ns_triplets) { + tempPool.ptr[-1] = namespaceSeparator; + s = b->prefix->name; + do { + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + } while (*s++); + } + appAtts[i] = poolStart(&tempPool); poolFinish(&tempPool); }