MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathIdFunction

Function xmlXPathIdFunction

ThirdParty/libxml2/vtklibxml2/xpath.c:7567–7615  ·  view source on GitHub ↗

* xmlXPathIdFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the id() XPath function * node-set id(object) * The id function selects elements by their unique ID * (see [5.2.1 Unique IDs]). When the argument to id is of type node-set, * then the result is the union of the result of applying id to the * string value of each of the nodes in the

Source from the content-addressed store, hash-verified

7565 * have a unique ID equal to any of the tokens in the list.
7566 */
7567void
7568xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs) {
7569 xmlChar *tokens;
7570 xmlNodeSetPtr ret;
7571 xmlXPathObjectPtr obj;
7572
7573 CHECK_ARITY(1);
7574 obj = valuePop(ctxt);
7575 if (obj == NULL) XP_ERROR(XPATH_INVALID_OPERAND);
7576 if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) {
7577 xmlNodeSetPtr ns;
7578 int i;
7579
7580 ret = xmlXPathNodeSetCreate(NULL);
7581 if (ret == NULL)
7582 xmlXPathPErrMemory(ctxt);
7583
7584 if (obj->nodesetval != NULL) {
7585 for (i = 0; i < obj->nodesetval->nodeNr; i++) {
7586 tokens =
7587 xmlXPathCastNodeToString(obj->nodesetval->nodeTab[i]);
7588 if (tokens == NULL)
7589 xmlXPathPErrMemory(ctxt);
7590 ns = xmlXPathGetElementsByIds(ctxt->context->doc, tokens);
7591 if (ns == NULL)
7592 xmlXPathPErrMemory(ctxt);
7593 ret = xmlXPathNodeSetMerge(ret, ns);
7594 if (ret == NULL)
7595 xmlXPathPErrMemory(ctxt);
7596 xmlXPathFreeNodeSet(ns);
7597 if (tokens != NULL)
7598 xmlFree(tokens);
7599 }
7600 }
7601 xmlXPathReleaseObject(ctxt->context, obj);
7602 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt, ret));
7603 return;
7604 }
7605 tokens = xmlXPathCastToString(obj);
7606 if (tokens == NULL)
7607 xmlXPathPErrMemory(ctxt);
7608 xmlXPathReleaseObject(ctxt->context, obj);
7609 ret = xmlXPathGetElementsByIds(ctxt->context->doc, tokens);
7610 if (ret == NULL)
7611 xmlXPathPErrMemory(ctxt);
7612 xmlFree(tokens);
7613 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt, ret));
7614 return;
7615}
7616
7617/**
7618 * xmlXPathLocalNameFunction:

Callers 1

xmlXPtrEvalChildSeqFunction · 0.85

Calls 11

valuePopFunction · 0.85
xmlXPathNodeSetCreateFunction · 0.85
xmlXPathPErrMemoryFunction · 0.85
xmlXPathCastNodeToStringFunction · 0.85
xmlXPathGetElementsByIdsFunction · 0.85
xmlXPathNodeSetMergeFunction · 0.85
xmlXPathFreeNodeSetFunction · 0.85
xmlXPathReleaseObjectFunction · 0.85
valuePushFunction · 0.85
xmlXPathCacheWrapNodeSetFunction · 0.85
xmlXPathCastToStringFunction · 0.85

Tested by

no test coverage detected