* xmlValidGetElemDecl: * @ctxt: the validation context * @doc: a document instance * @elem: an element instance * @extsubset: pointer, (out) indicate if the declaration was found * in the external subset. * * Finds a declaration associated to an element in the document. * * returns the pointer to the declaration or NULL if not found. */
| 5509 | * returns the pointer to the declaration or NULL if not found. |
| 5510 | */ |
| 5511 | static xmlElementPtr |
| 5512 | xmlValidGetElemDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, |
| 5513 | xmlNodePtr elem, int *extsubset) { |
| 5514 | xmlElementPtr elemDecl = NULL; |
| 5515 | const xmlChar *prefix = NULL; |
| 5516 | |
| 5517 | if ((ctxt == NULL) || (doc == NULL) || |
| 5518 | (elem == NULL) || (elem->name == NULL)) |
| 5519 | return(NULL); |
| 5520 | if (extsubset != NULL) |
| 5521 | *extsubset = 0; |
| 5522 | |
| 5523 | /* |
| 5524 | * Fetch the declaration for the qualified name |
| 5525 | */ |
| 5526 | if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) |
| 5527 | prefix = elem->ns->prefix; |
| 5528 | |
| 5529 | if (prefix != NULL) { |
| 5530 | elemDecl = xmlGetDtdQElementDesc(doc->intSubset, |
| 5531 | elem->name, prefix); |
| 5532 | if ((elemDecl == NULL) && (doc->extSubset != NULL)) { |
| 5533 | elemDecl = xmlGetDtdQElementDesc(doc->extSubset, |
| 5534 | elem->name, prefix); |
| 5535 | if ((elemDecl != NULL) && (extsubset != NULL)) |
| 5536 | *extsubset = 1; |
| 5537 | } |
| 5538 | } |
| 5539 | |
| 5540 | /* |
| 5541 | * Fetch the declaration for the non qualified name |
| 5542 | * This is "non-strict" validation should be done on the |
| 5543 | * full QName but in that case being flexible makes sense. |
| 5544 | */ |
| 5545 | if (elemDecl == NULL) { |
| 5546 | elemDecl = xmlGetDtdQElementDesc(doc->intSubset, elem->name, NULL); |
| 5547 | if ((elemDecl == NULL) && (doc->extSubset != NULL)) { |
| 5548 | elemDecl = xmlGetDtdQElementDesc(doc->extSubset, elem->name, NULL); |
| 5549 | if ((elemDecl != NULL) && (extsubset != NULL)) |
| 5550 | *extsubset = 1; |
| 5551 | } |
| 5552 | } |
| 5553 | if (elemDecl == NULL) { |
| 5554 | xmlErrValidNode(ctxt, elem, |
| 5555 | XML_DTD_UNKNOWN_ELEM, |
| 5556 | "No declaration for element %s\n", |
| 5557 | elem->name, NULL, NULL); |
| 5558 | } |
| 5559 | return(elemDecl); |
| 5560 | } |
| 5561 | |
| 5562 | #ifdef LIBXML_REGEXP_ENABLED |
| 5563 | /** |
no test coverage detected