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

Function xmlTextWriterStartAttributeNS

ThirdParty/libxml2/vtklibxml2/xmlwriter.c:1820–1899  ·  view source on GitHub ↗

* xmlTextWriterStartAttributeNS: * @writer: the xmlTextWriterPtr * @prefix: namespace prefix or NULL * @name: element local name * @namespaceURI: namespace URI or NULL * * Start an xml attribute with namespace support. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */

Source from the content-addressed store, hash-verified

1818 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1819 */
1820int
1821xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer,
1822 const xmlChar * prefix, const xmlChar * name,
1823 const xmlChar * namespaceURI)
1824{
1825 int count;
1826 int sum;
1827 xmlChar *buf;
1828 xmlTextWriterNsStackEntry *p;
1829
1830 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1831 return -1;
1832
1833 /* Handle namespace first in case of error */
1834 if (namespaceURI != 0) {
1835 xmlTextWriterNsStackEntry nsentry, *curns;
1836
1837 buf = xmlStrdup(BAD_CAST "xmlns");
1838 if (prefix != 0) {
1839 buf = xmlStrcat(buf, BAD_CAST ":");
1840 buf = xmlStrcat(buf, prefix);
1841 }
1842
1843 nsentry.prefix = buf;
1844 nsentry.uri = (xmlChar *)namespaceURI;
1845 nsentry.elem = xmlListFront(writer->nodes);
1846
1847 curns = (xmlTextWriterNsStackEntry *)xmlListSearch(writer->nsstack,
1848 (void *)&nsentry);
1849 if ((curns != NULL)) {
1850 xmlFree(buf);
1851 if (xmlStrcmp(curns->uri, namespaceURI) == 0) {
1852 /* Namespace already defined on element skip */
1853 buf = NULL;
1854 } else {
1855 /* Prefix mismatch so error out */
1856 return -1;
1857 }
1858 }
1859
1860 /* Do not add namespace decl to list - it is already there */
1861 if (buf != NULL) {
1862 p = (xmlTextWriterNsStackEntry *)
1863 xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
1864 if (p == 0) {
1865 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1866 "xmlTextWriterStartAttributeNS : out of memory!\n");
1867 return -1;
1868 }
1869
1870 p->prefix = buf;
1871 p->uri = xmlStrdup(namespaceURI);
1872 if (p->uri == 0) {
1873 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1874 "xmlTextWriterStartAttributeNS : out of memory!\n");
1875 xmlFree(p);
1876 return -1;
1877 }

Callers 1

Calls 8

xmlStrdupFunction · 0.85
xmlStrcatFunction · 0.85
xmlListFrontFunction · 0.85
xmlListSearchFunction · 0.85
xmlStrcmpFunction · 0.85
xmlWriterErrMsgFunction · 0.85
xmlListPushFrontFunction · 0.85

Tested by

no test coverage detected