MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlNewReference

Function xmlNewReference

ThirdParty/libxml2/vtklibxml2/tree.c:2471–2521  ·  view source on GitHub ↗

* xmlNewReference: * @doc: the target document (optional) * @name: the entity name * * Create a new entity reference node, linking the result with the * entity in @doc if found. * * Entity names like '&entity;' are handled as well. * * Returns a pointer to the new node object or NULL if arguments are * invalid or a memory allocation failed. */

Source from the content-addressed store, hash-verified

2469 * invalid or a memory allocation failed.
2470 */
2471xmlNodePtr
2472xmlNewReference(const xmlDoc *doc, const xmlChar *name) {
2473 xmlNodePtr cur;
2474 xmlEntityPtr ent;
2475
2476 if (name == NULL)
2477 return(NULL);
2478
2479 /*
2480 * Allocate a new node and fill the fields.
2481 */
2482 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
2483 if (cur == NULL)
2484 return(NULL);
2485 memset(cur, 0, sizeof(xmlNode));
2486 cur->type = XML_ENTITY_REF_NODE;
2487
2488 cur->doc = (xmlDoc *)doc;
2489 if (name[0] == '&') {
2490 int len;
2491 name++;
2492 len = xmlStrlen(name);
2493 if (name[len - 1] == ';')
2494 cur->name = xmlStrndup(name, len - 1);
2495 else
2496 cur->name = xmlStrndup(name, len);
2497 } else
2498 cur->name = xmlStrdup(name);
2499 if (cur->name == NULL)
2500 goto error;
2501
2502 ent = xmlGetDocEntity(doc, cur->name);
2503 if (ent != NULL) {
2504 cur->content = ent->content;
2505 /*
2506 * The parent pointer in entity is a DTD pointer and thus is NOT
2507 * updated. Not sure if this is 100% correct.
2508 * -George
2509 */
2510 cur->children = (xmlNodePtr) ent;
2511 cur->last = (xmlNodePtr) ent;
2512 }
2513
2514 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
2515 xmlRegisterNodeDefaultValue(cur);
2516 return(cur);
2517
2518error:
2519 xmlFreeNode(cur);
2520 return(NULL);
2521}
2522
2523/**
2524 * xmlNewDocText:

Callers 1

xmlSAX2ReferenceFunction · 0.85

Calls 5

xmlStrlenFunction · 0.85
xmlStrndupFunction · 0.85
xmlStrdupFunction · 0.85
xmlGetDocEntityFunction · 0.85
xmlFreeNodeFunction · 0.85

Tested by

no test coverage detected