* xmlXPathNodeSetAddNs: * @cur: the initial node set * @node: the hosting node * @ns: a the namespace node * * add a new namespace node to an existing NodeSet * * Returns 0 in case of success and -1 in case of error */
| 2846 | * Returns 0 in case of success and -1 in case of error |
| 2847 | */ |
| 2848 | int |
| 2849 | xmlXPathNodeSetAddNs(xmlNodeSetPtr cur, xmlNodePtr node, xmlNsPtr ns) { |
| 2850 | int i; |
| 2851 | xmlNodePtr nsNode; |
| 2852 | |
| 2853 | if ((cur == NULL) || (ns == NULL) || (node == NULL) || |
| 2854 | (ns->type != XML_NAMESPACE_DECL) || |
| 2855 | (node->type != XML_ELEMENT_NODE)) |
| 2856 | return(-1); |
| 2857 | |
| 2858 | /* @@ with_ns to check whether namespace nodes should be looked at @@ */ |
| 2859 | /* |
| 2860 | * prevent duplicates |
| 2861 | */ |
| 2862 | for (i = 0;i < cur->nodeNr;i++) { |
| 2863 | if ((cur->nodeTab[i] != NULL) && |
| 2864 | (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) && |
| 2865 | (((xmlNsPtr)cur->nodeTab[i])->next == (xmlNsPtr) node) && |
| 2866 | (xmlStrEqual(ns->prefix, ((xmlNsPtr)cur->nodeTab[i])->prefix))) |
| 2867 | return(0); |
| 2868 | } |
| 2869 | |
| 2870 | /* |
| 2871 | * grow the nodeTab if needed |
| 2872 | */ |
| 2873 | if (cur->nodeMax == 0) { |
| 2874 | cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * |
| 2875 | sizeof(xmlNodePtr)); |
| 2876 | if (cur->nodeTab == NULL) |
| 2877 | return(-1); |
| 2878 | memset(cur->nodeTab, 0 , |
| 2879 | XML_NODESET_DEFAULT * sizeof(xmlNodePtr)); |
| 2880 | cur->nodeMax = XML_NODESET_DEFAULT; |
| 2881 | } else if (cur->nodeNr == cur->nodeMax) { |
| 2882 | xmlNodePtr *temp; |
| 2883 | |
| 2884 | if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) |
| 2885 | return(-1); |
| 2886 | temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * |
| 2887 | sizeof(xmlNodePtr)); |
| 2888 | if (temp == NULL) |
| 2889 | return(-1); |
| 2890 | cur->nodeMax *= 2; |
| 2891 | cur->nodeTab = temp; |
| 2892 | } |
| 2893 | nsNode = xmlXPathNodeSetDupNs(node, ns); |
| 2894 | if(nsNode == NULL) |
| 2895 | return(-1); |
| 2896 | cur->nodeTab[cur->nodeNr++] = nsNode; |
| 2897 | return(0); |
| 2898 | } |
| 2899 | |
| 2900 | /** |
| 2901 | * xmlXPathNodeSetAdd: |
nothing calls this directly
no test coverage detected