mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-15 00:38:15 +00:00
Changes for namespace triplets.
This commit is contained in:
parent
24a3551e56
commit
91ae02924d
3 changed files with 65 additions and 4 deletions
|
@ -389,8 +389,8 @@ namespace declaration handlers with
|
|||
<code>XML_SetNamespaceDeclHandler</code></a>.
|
||||
|
||||
<p>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 <code>XML_ParserCreateNS</code>), 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.
|
||||
|
||||
<p>However if <a href="XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a>
|
||||
has been called with a non-zero <code>do_nst</code> parameter, then the
|
||||
expanded form for names with an explicit prefix is a concatenation of:
|
||||
URI, separator, local name, separator, prefix.
|
||||
</p>
|
||||
|
||||
<p>You can set handlers for the start of a namespace declaration and for
|
||||
the end of a scope of a declaration with the
|
||||
<code>XML_SetNamespaceDeclHandler</code> function.
|
||||
|
@ -1435,5 +1441,25 @@ The choices for <code>code</code> are:
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="fcndec"><a name="XML_SetReturnNSTriplet"><pre>
|
||||
void
|
||||
XML_SetReturnNSTriplet(XML_Parser parser,
|
||||
int do_nst);
|
||||
</pre></a></div>
|
||||
<div class="fcndef">
|
||||
<p>
|
||||
This function only has an effect when using a parser created with
|
||||
<a href="#XML_ParserCreateNS">XML_ParserCreateNS</a>, i.e. when namespace
|
||||
processing is in effect. The <code>do_nst</code> sets whether or not prefixes
|
||||
are returned with names qualified with a namespace prefix. If this function
|
||||
is called with <code>do_nst</code> 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.</p>
|
||||
<p>If <code>do_nst</code> is zero, then namespaces are reported in the
|
||||
default manner, URI then local_name separated by the namespace separator.</p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue