| 2985 | */ |
| 2986 | |
| 2987 | static xmlElementPtr |
| 2988 | xmlGetDtdElementDesc2(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *name) { |
| 2989 | xmlElementTablePtr table; |
| 2990 | xmlElementPtr cur = NULL; |
| 2991 | const xmlChar *localName; |
| 2992 | xmlChar *prefix = NULL; |
| 2993 | |
| 2994 | if (dtd == NULL) return(NULL); |
| 2995 | |
| 2996 | /* |
| 2997 | * Create the Element table if needed. |
| 2998 | */ |
| 2999 | if (dtd->elements == NULL) { |
| 3000 | xmlDictPtr dict = NULL; |
| 3001 | |
| 3002 | if (dtd->doc != NULL) |
| 3003 | dict = dtd->doc->dict; |
| 3004 | |
| 3005 | dtd->elements = xmlHashCreateDict(0, dict); |
| 3006 | if (dtd->elements == NULL) |
| 3007 | goto mem_error; |
| 3008 | } |
| 3009 | table = (xmlElementTablePtr) dtd->elements; |
| 3010 | |
| 3011 | localName = xmlSplitQName4(name, &prefix); |
| 3012 | if (localName == NULL) |
| 3013 | goto mem_error; |
| 3014 | cur = xmlHashLookup2(table, localName, prefix); |
| 3015 | if (cur == NULL) { |
| 3016 | cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement)); |
| 3017 | if (cur == NULL) |
| 3018 | goto mem_error; |
| 3019 | memset(cur, 0, sizeof(xmlElement)); |
| 3020 | cur->type = XML_ELEMENT_DECL; |
| 3021 | cur->doc = dtd->doc; |
| 3022 | |
| 3023 | /* |
| 3024 | * fill the structure. |
| 3025 | */ |
| 3026 | cur->name = xmlStrdup(localName); |
| 3027 | if (cur->name == NULL) |
| 3028 | goto mem_error; |
| 3029 | cur->prefix = prefix; |
| 3030 | prefix = NULL; |
| 3031 | cur->etype = XML_ELEMENT_TYPE_UNDEFINED; |
| 3032 | |
| 3033 | if (xmlHashAdd2(table, localName, cur->prefix, cur) <= 0) |
| 3034 | goto mem_error; |
| 3035 | } |
| 3036 | |
| 3037 | if (prefix != NULL) |
| 3038 | xmlFree(prefix); |
| 3039 | return(cur); |
| 3040 | |
| 3041 | mem_error: |
| 3042 | xmlVErrMemory(ctxt); |
| 3043 | xmlFree(prefix); |
| 3044 | xmlFreeElement(cur); |
no test coverage detected