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

Function xmlNewNs

ThirdParty/libxml2/vtklibxml2/tree.c:721–775  ·  view source on GitHub ↗

* xmlNewNs: * @node: the element carrying the namespace (optional) * @href: the URI associated * @prefix: the prefix for the namespace (optional) * * Create a new namespace. For a default namespace, @prefix should be * NULL. The namespace URI in @href is not checked. You should make sure * to pass a valid URI. * * If @node is provided, it must be an element node. The namespace will *

Source from the content-addressed store, hash-verified

719 * the prefix is already in use or a memory allocation failed.
720 */
721xmlNsPtr
722xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix) {
723 xmlNsPtr cur;
724
725 if ((node != NULL) && (node->type != XML_ELEMENT_NODE))
726 return(NULL);
727
728 /*
729 * Allocate a new Namespace and fill the fields.
730 */
731 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
732 if (cur == NULL)
733 return(NULL);
734 memset(cur, 0, sizeof(xmlNs));
735 cur->type = XML_LOCAL_NAMESPACE;
736
737 if (href != NULL) {
738 cur->href = xmlStrdup(href);
739 if (cur->href == NULL)
740 goto error;
741 }
742 if (prefix != NULL) {
743 cur->prefix = xmlStrdup(prefix);
744 if (cur->prefix == NULL)
745 goto error;
746 }
747
748 /*
749 * Add it at the end to preserve parsing order ...
750 * and checks for existing use of the prefix
751 */
752 if (node != NULL) {
753 if (node->nsDef == NULL) {
754 node->nsDef = cur;
755 } else {
756 xmlNsPtr prev = node->nsDef;
757
758 if ((xmlStrEqual(prev->prefix, cur->prefix)) &&
759 (prev->href != NULL))
760 goto error;
761 while (prev->next != NULL) {
762 prev = prev->next;
763 if ((xmlStrEqual(prev->prefix, cur->prefix)) &&
764 (prev->href != NULL))
765 goto error;
766 }
767 prev->next = cur;
768 }
769 }
770 return(cur);
771
772error:
773 xmlFreeNs(cur);
774 return(NULL);
775}
776
777/**
778 * xmlSetNs:

Callers 11

xmlDumpXMLCatalogFunction · 0.85
SAX2.cFile · 0.85
xmlSAX2StartElementFunction · 0.85
xmlSAX2StartElementNsFunction · 0.85
xmlCopyNamespaceFunction · 0.85
xmlCopyPropInternalFunction · 0.85
xmlStaticCopyNodeFunction · 0.85
xmlNewReconciledNsFunction · 0.85
xmlDOMWrapStoreNsFunction · 0.85

Calls 3

xmlStrdupFunction · 0.85
xmlStrEqualFunction · 0.85
xmlFreeNsFunction · 0.85

Tested by

no test coverage detected