* xmlSAX2AttributeDecl: * @ctx: the user data (XML parser context) * @elem: the name of the element * @fullname: the attribute name * @type: the attribute type * @def: the type of default value * @defaultValue: the attribute default value * @tree: the tree of enumerated value set * * An attribute definition has been parsed */
| 619 | * An attribute definition has been parsed |
| 620 | */ |
| 621 | void |
| 622 | xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, |
| 623 | int type, int def, const xmlChar *defaultValue, |
| 624 | xmlEnumerationPtr tree) |
| 625 | { |
| 626 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 627 | xmlAttributePtr attr; |
| 628 | xmlChar *name = NULL, *prefix = NULL; |
| 629 | |
| 630 | /* Avoid unused variable warning if features are disabled. */ |
| 631 | (void) attr; |
| 632 | |
| 633 | if ((ctxt == NULL) || (ctxt->myDoc == NULL)) |
| 634 | return; |
| 635 | |
| 636 | if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) && |
| 637 | (type != XML_ATTRIBUTE_ID)) { |
| 638 | /* |
| 639 | * Raise the error but keep the validity flag |
| 640 | */ |
| 641 | int tmp = ctxt->valid; |
| 642 | xmlErrValid(ctxt, XML_DTD_XMLID_TYPE, |
| 643 | "xml:id : attribute type should be ID\n", NULL, NULL); |
| 644 | ctxt->valid = tmp; |
| 645 | } |
| 646 | /* TODO: optimize name/prefix allocation */ |
| 647 | name = xmlSplitQName(ctxt, fullname, &prefix); |
| 648 | if (name == NULL) |
| 649 | xmlSAX2ErrMemory(ctxt); |
| 650 | ctxt->vctxt.valid = 1; |
| 651 | if (ctxt->inSubset == 1) |
| 652 | attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem, |
| 653 | name, prefix, (xmlAttributeType) type, |
| 654 | (xmlAttributeDefault) def, defaultValue, tree); |
| 655 | else if (ctxt->inSubset == 2) |
| 656 | attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem, |
| 657 | name, prefix, (xmlAttributeType) type, |
| 658 | (xmlAttributeDefault) def, defaultValue, tree); |
| 659 | else { |
| 660 | xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, |
| 661 | "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n", |
| 662 | name, NULL); |
| 663 | xmlFree(name); |
| 664 | xmlFree(prefix); |
| 665 | xmlFreeEnumeration(tree); |
| 666 | return; |
| 667 | } |
| 668 | #ifdef LIBXML_VALID_ENABLED |
| 669 | if (ctxt->vctxt.valid == 0) |
| 670 | ctxt->valid = 0; |
| 671 | if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) && |
| 672 | (ctxt->myDoc->intSubset != NULL)) |
| 673 | ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, |
| 674 | attr); |
| 675 | #endif /* LIBXML_VALID_ENABLED */ |
| 676 | if (prefix != NULL) |
| 677 | xmlFree(prefix); |
| 678 | if (name != NULL) |
no test coverage detected