* xmlNewTextChild: * @parent: the parent node * @ns: a namespace (optional) * @name: the name of the child * @content: raw text content of the child (optional) * * Create a new child element and append it to a parent element. * * If @ns is NULL, the newly created element inherits the namespace * of the parent. * * If @content is provided, a text node will be added to the child * el
| 2336 | * are invalid or a memory allocation failed. |
| 2337 | */ |
| 2338 | xmlNodePtr |
| 2339 | xmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns, |
| 2340 | const xmlChar *name, const xmlChar *content) { |
| 2341 | xmlNodePtr cur, prev; |
| 2342 | |
| 2343 | if ((parent == NULL) || (name == NULL)) |
| 2344 | return(NULL); |
| 2345 | |
| 2346 | switch (parent->type) { |
| 2347 | case XML_DOCUMENT_NODE: |
| 2348 | case XML_HTML_DOCUMENT_NODE: |
| 2349 | case XML_DOCUMENT_FRAG_NODE: |
| 2350 | break; |
| 2351 | |
| 2352 | case XML_ELEMENT_NODE: |
| 2353 | if (ns == NULL) |
| 2354 | ns = parent->ns; |
| 2355 | break; |
| 2356 | |
| 2357 | default: |
| 2358 | return(NULL); |
| 2359 | } |
| 2360 | |
| 2361 | cur = xmlNewDocRawNode(parent->doc, ns, name, content); |
| 2362 | if (cur == NULL) |
| 2363 | return(NULL); |
| 2364 | |
| 2365 | /* |
| 2366 | * add the new element at the end of the children list. |
| 2367 | */ |
| 2368 | cur->parent = parent; |
| 2369 | if (parent->children == NULL) { |
| 2370 | parent->children = cur; |
| 2371 | parent->last = cur; |
| 2372 | } else { |
| 2373 | prev = parent->last; |
| 2374 | prev->next = cur; |
| 2375 | cur->prev = prev; |
| 2376 | parent->last = cur; |
| 2377 | } |
| 2378 | |
| 2379 | return(cur); |
| 2380 | } |
| 2381 | #endif /* LIBXML_TREE_ENABLED */ |
| 2382 | |
| 2383 | /** |
nothing calls this directly
no test coverage detected