* xmlIsID: * @doc: the document * @elem: the element carrying the attribute * @attr: the attribute * * Determine whether an attribute is of type ID. In case we have DTD(s) * then this is done if DTD loading has been requested. In the case * of HTML documents parsed with the HTML parser, then ID detection is * done systematically. * * Returns 0 or 1 depending on the lookup result or -1
| 2472 | * failed. |
| 2473 | */ |
| 2474 | int |
| 2475 | xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { |
| 2476 | if ((attr == NULL) || (attr->name == NULL)) |
| 2477 | return(0); |
| 2478 | |
| 2479 | if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { |
| 2480 | if (xmlStrEqual(BAD_CAST "id", attr->name)) |
| 2481 | return(1); |
| 2482 | |
| 2483 | if ((elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
| 2484 | return(0); |
| 2485 | |
| 2486 | if ((xmlStrEqual(BAD_CAST "name", attr->name)) && |
| 2487 | (xmlStrEqual(elem->name, BAD_CAST "a"))) |
| 2488 | return(1); |
| 2489 | } else { |
| 2490 | xmlAttributePtr attrDecl = NULL; |
| 2491 | xmlChar felem[50]; |
| 2492 | xmlChar *fullelemname; |
| 2493 | const xmlChar *aprefix; |
| 2494 | |
| 2495 | if ((attr->ns != NULL) && (attr->ns->prefix != NULL) && |
| 2496 | (!strcmp((char *) attr->name, "id")) && |
| 2497 | (!strcmp((char *) attr->ns->prefix, "xml"))) |
| 2498 | return(1); |
| 2499 | |
| 2500 | if ((doc == NULL) || |
| 2501 | ((doc->intSubset == NULL) && (doc->extSubset == NULL))) |
| 2502 | return(0); |
| 2503 | |
| 2504 | if ((elem == NULL) || |
| 2505 | (elem->type != XML_ELEMENT_NODE) || |
| 2506 | (elem->name == NULL)) |
| 2507 | return(0); |
| 2508 | |
| 2509 | fullelemname = (elem->ns != NULL && elem->ns->prefix != NULL) ? |
| 2510 | xmlBuildQName(elem->name, elem->ns->prefix, felem, 50) : |
| 2511 | (xmlChar *)elem->name; |
| 2512 | if (fullelemname == NULL) |
| 2513 | return(-1); |
| 2514 | |
| 2515 | aprefix = (attr->ns != NULL) ? attr->ns->prefix : NULL; |
| 2516 | |
| 2517 | if (fullelemname != NULL) { |
| 2518 | attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, fullelemname, |
| 2519 | attr->name, aprefix); |
| 2520 | if ((attrDecl == NULL) && (doc->extSubset != NULL)) |
| 2521 | attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, fullelemname, |
| 2522 | attr->name, aprefix); |
| 2523 | } |
| 2524 | |
| 2525 | if ((fullelemname != felem) && (fullelemname != elem->name)) |
| 2526 | xmlFree(fullelemname); |
| 2527 | |
| 2528 | if ((attrDecl != NULL) && (attrDecl->atype == XML_ATTRIBUTE_ID)) |
| 2529 | return(1); |
| 2530 | } |
| 2531 |
no test coverage detected