* xmlNewDocProp: * @doc: the target document (optional) * @name: the name of the attribute * @value: attribute value with XML references (optional) * * Create an attribute object. * * If provided, @value is expected to be a valid XML attribute value * possibly containing character and entity references. Syntax errors * and references to undeclared entities are ignored silently. * If y
| 1857 | * or a memory allocation failed. |
| 1858 | */ |
| 1859 | xmlAttrPtr |
| 1860 | xmlNewDocProp(xmlDocPtr doc, const xmlChar *name, const xmlChar *value) { |
| 1861 | xmlAttrPtr cur; |
| 1862 | |
| 1863 | if (name == NULL) { |
| 1864 | return(NULL); |
| 1865 | } |
| 1866 | |
| 1867 | /* |
| 1868 | * Allocate a new property and fill the fields. |
| 1869 | */ |
| 1870 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
| 1871 | if (cur == NULL) |
| 1872 | return(NULL); |
| 1873 | memset(cur, 0, sizeof(xmlAttr)); |
| 1874 | cur->type = XML_ATTRIBUTE_NODE; |
| 1875 | |
| 1876 | if ((doc != NULL) && (doc->dict != NULL)) |
| 1877 | cur->name = xmlDictLookup(doc->dict, name, -1); |
| 1878 | else |
| 1879 | cur->name = xmlStrdup(name); |
| 1880 | if (cur->name == NULL) |
| 1881 | goto error; |
| 1882 | cur->doc = doc; |
| 1883 | if (value != NULL) { |
| 1884 | if (xmlNodeParseContent((xmlNodePtr) cur, value, -1) < 0) |
| 1885 | goto error; |
| 1886 | } |
| 1887 | |
| 1888 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| 1889 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| 1890 | return(cur); |
| 1891 | |
| 1892 | error: |
| 1893 | xmlFreeProp(cur); |
| 1894 | return(NULL); |
| 1895 | } |
| 1896 | |
| 1897 | /** |
| 1898 | * xmlFreePropList: |
no test coverage detected