If the node passed to xmlNodeGetContent is NULL the return value will be NULL:
xmlNode *current_node = NULL;
xmlChar *ret_val;
ret_val = xmlNodeGetContent(current_node);
if(ret_val == NULL)
printf("ret_val is NULL\n");
If the node is a Valid xmlNode, the function could return NULL in different cases, you can check the function in tree.c:
xmlChar *xmlNodeGetContent(const xmlNode *cur)
{
if(cur == NULL)
return (NULL);
switch(cur->type)
{
case XML_DOCUMENT_FRAG_NODE:
case XML_ELEMENT_NODE:
{
xmlBufPtr buf;
xmlChar *ret;
buf = xmlBufCreateSize(64);
if(buf == NULL)
return (NULL);
xmlBufGetNodeContent(buf, cur);
ret = xmlBufDetach(buf);
xmlBufFree(buf);
return (ret);
}
case XML_ATTRIBUTE_NODE:
return (xmlGetPropNodeValueInternal((xmlAttrPtr)cur));
case XML_COMMENT_NODE:
case XML_PI_NODE:
if(cur->content != NULL)
return (xmlStrdup(cur->content));
return (NULL);
case XML_ENTITY_REF_NODE:
{
xmlEntityPtr ent;
xmlBufPtr buf;
xmlChar *ret;
/* lookup entity declaration */
ent = xmlGetDocEntity(cur->doc, cur->name);
if(ent == NULL)
return (NULL);
buf = xmlBufCreate();
if(buf == NULL)
return (NULL);
xmlBufGetNodeContent(buf, cur);
ret = xmlBufDetach(buf);
xmlBufFree(buf);
return (ret);
}
case XML_ENTITY_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
return (NULL);
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
{
xmlBufPtr buf;
xmlChar *ret;
buf = xmlBufCreate();
if(buf == NULL)
return (NULL);
xmlBufGetNodeContent(buf, (xmlNodePtr)cur);
ret = xmlBufDetach(buf);
xmlBufFree(buf);
return (ret);
}
case XML_NAMESPACE_DECL:
{
xmlChar *tmp;
tmp = xmlStrdup(((xmlNsPtr)cur)->href);
return (tmp);
}
case XML_ELEMENT_DECL:
/* TODO !!! */
return (NULL);
case XML_ATTRIBUTE_DECL:
/* TODO !!! */
return (NULL);
case XML_ENTITY_DECL:
/* TODO !!! */
return (NULL);
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
if(cur->content != NULL)
return (xmlStrdup(cur->content));
return (NULL);
}
return (NULL);
}