* xmlNewDocPI: * @doc: the target document (optional) * @name: the processing instruction target * @content: the PI content (optional) * * Create a processing instruction object. * * Returns a pointer to the new node object or NULL if arguments are * invalid or a memory allocation failed. */
| 1991 | * invalid or a memory allocation failed. |
| 1992 | */ |
| 1993 | xmlNodePtr |
| 1994 | xmlNewDocPI(xmlDocPtr doc, const xmlChar *name, const xmlChar *content) { |
| 1995 | xmlNodePtr cur; |
| 1996 | |
| 1997 | if (name == NULL) { |
| 1998 | return(NULL); |
| 1999 | } |
| 2000 | |
| 2001 | /* |
| 2002 | * Allocate a new node and fill the fields. |
| 2003 | */ |
| 2004 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| 2005 | if (cur == NULL) |
| 2006 | return(NULL); |
| 2007 | memset(cur, 0, sizeof(xmlNode)); |
| 2008 | cur->type = XML_PI_NODE; |
| 2009 | cur->doc = doc; |
| 2010 | |
| 2011 | if ((doc != NULL) && (doc->dict != NULL)) |
| 2012 | cur->name = xmlDictLookup(doc->dict, name, -1); |
| 2013 | else |
| 2014 | cur->name = xmlStrdup(name); |
| 2015 | if (cur->name == NULL) |
| 2016 | goto error; |
| 2017 | if (content != NULL) { |
| 2018 | cur->content = xmlStrdup(content); |
| 2019 | if (cur->content == NULL) |
| 2020 | goto error; |
| 2021 | } |
| 2022 | |
| 2023 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| 2024 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| 2025 | return(cur); |
| 2026 | |
| 2027 | error: |
| 2028 | xmlFreeNode(cur); |
| 2029 | return(NULL); |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * xmlNewPI: |
no test coverage detected