* xmlAddRef: * @ctxt: the validation context * @doc: pointer to the document * @value: the value name * @attr: the attribute holding the Ref * * DEPRECATED, do not use. This function will be removed from the public API. * * Register a new ref declaration * * Returns NULL if not, otherwise the new xmlRefPtr */
| 2697 | * Returns NULL if not, otherwise the new xmlRefPtr |
| 2698 | */ |
| 2699 | xmlRefPtr |
| 2700 | xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, |
| 2701 | xmlAttrPtr attr) { |
| 2702 | xmlRefPtr ret = NULL; |
| 2703 | xmlRefTablePtr table; |
| 2704 | xmlListPtr ref_list; |
| 2705 | |
| 2706 | if (doc == NULL) { |
| 2707 | return(NULL); |
| 2708 | } |
| 2709 | if (value == NULL) { |
| 2710 | return(NULL); |
| 2711 | } |
| 2712 | if (attr == NULL) { |
| 2713 | return(NULL); |
| 2714 | } |
| 2715 | |
| 2716 | /* |
| 2717 | * Create the Ref table if needed. |
| 2718 | */ |
| 2719 | table = (xmlRefTablePtr) doc->refs; |
| 2720 | if (table == NULL) { |
| 2721 | doc->refs = table = xmlHashCreateDict(0, doc->dict); |
| 2722 | if (table == NULL) |
| 2723 | goto failed; |
| 2724 | } |
| 2725 | |
| 2726 | ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef)); |
| 2727 | if (ret == NULL) |
| 2728 | goto failed; |
| 2729 | memset(ret, 0, sizeof(*ret)); |
| 2730 | |
| 2731 | /* |
| 2732 | * fill the structure. |
| 2733 | */ |
| 2734 | ret->value = xmlStrdup(value); |
| 2735 | if (ret->value == NULL) |
| 2736 | goto failed; |
| 2737 | if (xmlIsStreaming(ctxt)) { |
| 2738 | /* |
| 2739 | * Operating in streaming mode, attr is gonna disappear |
| 2740 | */ |
| 2741 | ret->name = xmlStrdup(attr->name); |
| 2742 | if (ret->name == NULL) |
| 2743 | goto failed; |
| 2744 | ret->attr = NULL; |
| 2745 | } else { |
| 2746 | ret->name = NULL; |
| 2747 | ret->attr = attr; |
| 2748 | } |
| 2749 | ret->lineno = xmlGetLineNo(attr->parent); |
| 2750 | |
| 2751 | /* To add a reference :- |
| 2752 | * References are maintained as a list of references, |
| 2753 | * Lookup the entry, if no entry create new nodelist |
| 2754 | * Add the owning node to the NodeList |
| 2755 | * Return the ref |
| 2756 | */ |
no test coverage detected