* xmlSAX2AttributeNs: * @ctx: the user data (XML parser context) * @localname: the local name of the attribute * @prefix: the attribute namespace prefix if available * @URI: the attribute namespace name if available * @value: Start of the attribute value * @valueend: end of the attribute value * * Handle an attribute that has been read by the parser. * The default handling is to conve
| 1826 | * Returns the new attribute or NULL in case of error. |
| 1827 | */ |
| 1828 | static xmlAttrPtr |
| 1829 | xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, |
| 1830 | const xmlChar * localname, |
| 1831 | const xmlChar * prefix, |
| 1832 | const xmlChar * value, |
| 1833 | const xmlChar * valueend) |
| 1834 | { |
| 1835 | xmlAttrPtr ret; |
| 1836 | xmlNsPtr namespace = NULL; |
| 1837 | xmlChar *dup = NULL; |
| 1838 | |
| 1839 | /* |
| 1840 | * Note: if prefix == NULL, the attribute is not in the default namespace |
| 1841 | */ |
| 1842 | if (prefix != NULL) { |
| 1843 | namespace = xmlParserNsLookupSax(ctxt, prefix); |
| 1844 | if ((namespace == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { |
| 1845 | int res; |
| 1846 | |
| 1847 | res = xmlSearchNsSafe(ctxt->node, prefix, &namespace); |
| 1848 | if (res < 0) |
| 1849 | xmlSAX2ErrMemory(ctxt); |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | /* |
| 1854 | * allocate the node |
| 1855 | */ |
| 1856 | if (ctxt->freeAttrs != NULL) { |
| 1857 | ret = ctxt->freeAttrs; |
| 1858 | ctxt->freeAttrs = ret->next; |
| 1859 | ctxt->freeAttrsNr--; |
| 1860 | } else { |
| 1861 | ret = xmlMalloc(sizeof(*ret)); |
| 1862 | if (ret == NULL) { |
| 1863 | xmlSAX2ErrMemory(ctxt); |
| 1864 | return(NULL); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | memset(ret, 0, sizeof(xmlAttr)); |
| 1869 | ret->type = XML_ATTRIBUTE_NODE; |
| 1870 | |
| 1871 | /* |
| 1872 | * xmlParseBalancedChunkMemoryRecover had a bug that could result in |
| 1873 | * a mismatch between ctxt->node->doc and ctxt->myDoc. We use |
| 1874 | * ctxt->node->doc here, but we should somehow make sure that the |
| 1875 | * document pointers match. |
| 1876 | */ |
| 1877 | |
| 1878 | /* assert(ctxt->node->doc == ctxt->myDoc); */ |
| 1879 | |
| 1880 | ret->parent = ctxt->node; |
| 1881 | ret->doc = ctxt->node->doc; |
| 1882 | ret->ns = namespace; |
| 1883 | |
| 1884 | if (ctxt->dictNames) { |
| 1885 | ret->name = localname; |
no test coverage detected