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

Function xmlXPathGetElementsByIds

ThirdParty/libxml2/vtklibxml2/xpath.c:7495–7547  ·  view source on GitHub ↗

* xmlXPathGetElementsByIds: * @doc: the document * @ids: a whitespace separated list of IDs * * Selects elements by their unique ID. * * Returns a node-set of selected elements. */

Source from the content-addressed store, hash-verified

7493 * Returns a node-set of selected elements.
7494 */
7495static xmlNodeSetPtr
7496xmlXPathGetElementsByIds (xmlDocPtr doc, const xmlChar *ids) {
7497 xmlNodeSetPtr ret;
7498 const xmlChar *cur = ids;
7499 xmlChar *ID;
7500 xmlAttrPtr attr;
7501 xmlNodePtr elem = NULL;
7502
7503 if (ids == NULL) return(NULL);
7504
7505 ret = xmlXPathNodeSetCreate(NULL);
7506 if (ret == NULL)
7507 return(ret);
7508
7509 while (IS_BLANK_CH(*cur)) cur++;
7510 while (*cur != 0) {
7511 while ((!IS_BLANK_CH(*cur)) && (*cur != 0))
7512 cur++;
7513
7514 ID = xmlStrndup(ids, cur - ids);
7515 if (ID == NULL) {
7516 xmlXPathFreeNodeSet(ret);
7517 return(NULL);
7518 }
7519 /*
7520 * We used to check the fact that the value passed
7521 * was an NCName, but this generated much troubles for
7522 * me and Aleksey Sanin, people blatantly violated that
7523 * constraint, like Visa3D spec.
7524 * if (xmlValidateNCName(ID, 1) == 0)
7525 */
7526 attr = xmlGetID(doc, ID);
7527 xmlFree(ID);
7528 if (attr != NULL) {
7529 if (attr->type == XML_ATTRIBUTE_NODE)
7530 elem = attr->parent;
7531 else if (attr->type == XML_ELEMENT_NODE)
7532 elem = (xmlNodePtr) attr;
7533 else
7534 elem = NULL;
7535 if (elem != NULL) {
7536 if (xmlXPathNodeSetAdd(ret, elem) < 0) {
7537 xmlXPathFreeNodeSet(ret);
7538 return(NULL);
7539 }
7540 }
7541 }
7542
7543 while (IS_BLANK_CH(*cur)) cur++;
7544 ids = cur;
7545 }
7546 return(ret);
7547}
7548
7549/**
7550 * xmlXPathIdFunction:

Callers 1

xmlXPathIdFunctionFunction · 0.85

Calls 5

xmlXPathNodeSetCreateFunction · 0.85
xmlStrndupFunction · 0.85
xmlXPathFreeNodeSetFunction · 0.85
xmlGetIDFunction · 0.85
xmlXPathNodeSetAddFunction · 0.85

Tested by

no test coverage detected