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

Function xmlGetNsListSafe

ThirdParty/libxml2/vtklibxml2/tree.c:5912–5963  ·  view source on GitHub ↗

* xmlGetNsListSafe: * @doc: the document * @node: the current node * @out: the returned namespace array * * Find all in-scope namespaces of a node. @out returns a NULL * terminated array of namespace pointers that must be freed by * the caller. * * Available since 2.13.0. * * Returns 0 on success, 1 if no namespaces were found, -1 if a * memory allocation failed. */

Source from the content-addressed store, hash-verified

5910 * memory allocation failed.
5911 */
5912int
5913xmlGetNsListSafe(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlNode *node,
5914 xmlNsPtr **out)
5915{
5916 xmlNsPtr cur;
5917 xmlNsPtr *namespaces = NULL;
5918 int nbns = 0;
5919 int maxns = 0;
5920 int i;
5921
5922 if (out == NULL)
5923 return(1);
5924 *out = NULL;
5925 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
5926 return(1);
5927
5928 while (node != NULL) {
5929 if (node->type == XML_ELEMENT_NODE) {
5930 cur = node->nsDef;
5931 while (cur != NULL) {
5932 for (i = 0; i < nbns; i++) {
5933 if ((cur->prefix == namespaces[i]->prefix) ||
5934 (xmlStrEqual(cur->prefix, namespaces[i]->prefix)))
5935 break;
5936 }
5937 if (i >= nbns) {
5938 if (nbns >= maxns) {
5939 xmlNsPtr *tmp;
5940
5941 maxns = maxns ? maxns * 2 : 10;
5942 tmp = (xmlNsPtr *) xmlRealloc(namespaces,
5943 (maxns + 1) *
5944 sizeof(xmlNsPtr));
5945 if (tmp == NULL) {
5946 xmlFree(namespaces);
5947 return(-1);
5948 }
5949 namespaces = tmp;
5950 }
5951 namespaces[nbns++] = cur;
5952 namespaces[nbns] = NULL;
5953 }
5954
5955 cur = cur->next;
5956 }
5957 }
5958 node = node->parent;
5959 }
5960
5961 *out = namespaces;
5962 return((namespaces == NULL) ? 1 : 0);
5963}
5964
5965/**
5966 * xmlGetNsList:

Callers 2

xmlXPathNextNamespaceFunction · 0.85
xmlGetNsListFunction · 0.85

Calls 1

xmlStrEqualFunction · 0.85

Tested by

no test coverage detected