* xmlTextReaderGetAttribute: * @reader: the xmlTextReaderPtr used * @name: the qualified name of the attribute. * * Provides the value of the attribute with the specified qualified name. * * Returns a string containing the value of the specified attribute, or NULL * in case of error. The string must be deallocated by the caller. */
| 2360 | * in case of error. The string must be deallocated by the caller. |
| 2361 | */ |
| 2362 | xmlChar * |
| 2363 | xmlTextReaderGetAttribute(xmlTextReaderPtr reader, const xmlChar *name) { |
| 2364 | xmlChar *prefix = NULL; |
| 2365 | const xmlChar *localname; |
| 2366 | xmlNsPtr ns; |
| 2367 | xmlChar *ret = NULL; |
| 2368 | int result; |
| 2369 | |
| 2370 | if ((reader == NULL) || (name == NULL)) |
| 2371 | return(NULL); |
| 2372 | if (reader->node == NULL) |
| 2373 | return(NULL); |
| 2374 | if (reader->curnode != NULL) |
| 2375 | return(NULL); |
| 2376 | |
| 2377 | /* TODO: handle the xmlDecl */ |
| 2378 | if (reader->node->type != XML_ELEMENT_NODE) |
| 2379 | return(NULL); |
| 2380 | |
| 2381 | localname = xmlSplitQName4(name, &prefix); |
| 2382 | if (localname == NULL) { |
| 2383 | xmlTextReaderErrMemory(reader); |
| 2384 | return(NULL); |
| 2385 | } |
| 2386 | if (prefix == NULL) { |
| 2387 | /* |
| 2388 | * Namespace default decl |
| 2389 | */ |
| 2390 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { |
| 2391 | ns = reader->node->nsDef; |
| 2392 | while (ns != NULL) { |
| 2393 | if (ns->prefix == NULL) { |
| 2394 | return(readerStrdup(reader, ns->href)); |
| 2395 | } |
| 2396 | ns = ns->next; |
| 2397 | } |
| 2398 | return NULL; |
| 2399 | } |
| 2400 | |
| 2401 | result = xmlNodeGetAttrValue(reader->node, name, NULL, &ret); |
| 2402 | if (result < 0) |
| 2403 | xmlTextReaderErrMemory(reader); |
| 2404 | return(ret); |
| 2405 | } |
| 2406 | |
| 2407 | /* |
| 2408 | * Namespace default decl |
| 2409 | */ |
| 2410 | if (xmlStrEqual(prefix, BAD_CAST "xmlns")) { |
| 2411 | ns = reader->node->nsDef; |
| 2412 | while (ns != NULL) { |
| 2413 | if ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localname))) { |
| 2414 | ret = readerStrdup(reader, ns->href); |
| 2415 | break; |
| 2416 | } |
| 2417 | ns = ns->next; |
| 2418 | } |
| 2419 | } else { |
nothing calls this directly
no test coverage detected