72 if (nodeptr->nodeName) {
73 free(nodeptr->nodeName);
75 if (nodeptr->nodeValue) {
76 free(nodeptr->nodeValue);
78 if (nodeptr->namespaceURI) {
79 free(nodeptr->namespaceURI);
81 if (nodeptr->prefix) {
82 free(nodeptr->prefix);
84 if (nodeptr->localName) {
85 free(nodeptr->localName);
87 switch (nodeptr->nodeType) {
90 free(element->tagName);
106void ixmlNode_recursive_free(
IXML_Node *nodeptr)
109#ifdef IXML_HAVE_SCRIPTSUPPORT
110 IXML_BeforeFreeNode_t handler = Parser_getBeforeFree();
111 if (handler) handler(nodeptr);
132#ifdef IXML_HAVE_SCRIPTSUPPORT
133 IXML_BeforeFreeNode_t handler = Parser_getBeforeFree();
135 prev_child = nodeptr;
136 next_child = nodeptr->firstChild;
138 curr_child = next_child;
141 prev_child = curr_child;
142 curr_child = curr_child->firstChild;
144 curr_child = prev_child;
146 prev_child = curr_child;
147 curr_child = curr_child->nextSibling;
149 curr_child = prev_child;
150 next_child = curr_child->firstChild;
151 }
while (next_child);
155 curr_attr = curr_child->firstAttr;
157 next_attr = curr_attr->nextSibling;
159 curr_attr = next_attr;
161 curr_child->firstAttr = 0;
163 if (curr_child != nodeptr) {
164 if (curr_child->prevSibling) {
165 next_child = curr_child->prevSibling;
166 next_child->nextSibling = 0;
168 next_child = curr_child->parentNode;
169 next_child->firstChild = 0;
172#ifdef IXML_HAVE_SCRIPTSUPPORT
178 }
while (curr_child != nodeptr);
184 return nodeptr->nodeName;
192 return nodeptr->localName;
205 const char* namespaceURI) {
207 return IXML_INVALID_PARAMETER;
209 if (nodeptr->namespaceURI) {
210 free(nodeptr->namespaceURI);
211 nodeptr->namespaceURI = NULL;
214 nodeptr->namespaceURI = strdup(namespaceURI);
215 if (!nodeptr->namespaceURI) {
216 return IXML_INSUFFICIENT_MEMORY;
230 const char* prefix) {
232 return IXML_INVALID_PARAMETER;
234 if (nodeptr->prefix) {
235 free(nodeptr->prefix);
236 nodeptr->prefix = NULL;
239 nodeptr->prefix = strdup(prefix);
240 if (!nodeptr->prefix) {
241 return IXML_INSUFFICIENT_MEMORY;
257 const char* localName) {
260 if (nodeptr->localName) {
261 free(nodeptr->localName);
262 nodeptr->localName = NULL;
265 nodeptr->localName = strdup(localName);
266 if (!nodeptr->localName) {
267 return IXML_INSUFFICIENT_MEMORY;
278 retNamespaceURI = nodeptr->namespaceURI;
281 return retNamespaceURI;
288 prefix = nodeptr->prefix;
296 return nodeptr->nodeValue;
303 int rc = IXML_SUCCESS;
306 return IXML_INVALID_PARAMETER;
308 if (nodeptr->nodeValue) {
309 free(nodeptr->nodeValue);
310 nodeptr->nodeValue = NULL;
313 nodeptr->nodeValue = strdup(newNodeValue);
314 if (!nodeptr->nodeValue) {
315 return IXML_INSUFFICIENT_MEMORY;
324 return (
unsigned short)nodeptr->nodeType;
326 return (
unsigned short)eINVALID_NODE;
332 return nodeptr->parentNode;
340 return nodeptr->firstChild;
352 next = nodeptr->firstChild;
355 next = next->nextSibling;
365 return nodeptr->prevSibling;
373 return nodeptr->nextSibling;
399 if (ancestorNode && toFind) {
400 if (toFind->parentNode == ancestorNode) {
425 assert(nodeptr && toFind);
427 if (nodeptr && toFind) {
428 found = toFind->parentNode == nodeptr;
446 assert(nodeptr && newChild);
448 switch (nodeptr->nodeType) {
449 case eATTRIBUTE_NODE:
451 case eCDATA_SECTION_NODE:
454 switch (newChild->nodeType) {
455 case eATTRIBUTE_NODE:
463 switch (newChild->nodeType) {
490 assert(srcNode && destNode);
493 return srcNode == destNode ||
494 (strcmp(srcNode->nodeName, destNode->nodeName) == 0 &&
495 strcmp(srcNode->nodeValue, destNode->nodeValue) == 0 &&
496 srcNode->nodeType == destNode->nodeType &&
497 strcmp(srcNode->namespaceURI, destNode->namespaceURI) == 0 &&
498 strcmp(srcNode->prefix, destNode->prefix) == 0 &&
499 strcmp(srcNode->localName, destNode->localName) == 0);
505 int ret = IXML_SUCCESS;
507 if (!nodeptr || !newChild) {
508 return IXML_INVALID_PARAMETER;
512 return IXML_HIERARCHY_REQUEST_ERR;
516 return IXML_HIERARCHY_REQUEST_ERR;
519 if (nodeptr->ownerDocument != newChild->ownerDocument) {
520 return IXML_WRONG_DOCUMENT_ERR;
524 return IXML_NOT_FOUND_ERR;
529 newChild->nextSibling = NULL;
530 newChild->prevSibling = NULL;
532 newChild->nextSibling = refChild;
533 if (refChild->prevSibling) {
534 refChild->prevSibling->nextSibling = newChild;
535 newChild->prevSibling = refChild->prevSibling;
537 refChild->prevSibling = newChild;
538 if (!newChild->prevSibling) {
539 nodeptr->firstChild = newChild;
541 newChild->parentNode = nodeptr;
551 int ret = IXML_SUCCESS;
553 if (!nodeptr || !newChild || !oldChild) {
554 return IXML_INVALID_PARAMETER;
560 return IXML_HIERARCHY_REQUEST_ERR;
563 return IXML_HIERARCHY_REQUEST_ERR;
566 if (nodeptr->ownerDocument != newChild->ownerDocument) {
567 return IXML_WRONG_DOCUMENT_ERR;
571 return IXML_NOT_FOUND_ERR;
574 if (ret != IXML_SUCCESS) {
583 if (!nodeptr || !oldChild) {
584 return IXML_INVALID_PARAMETER;
587 return IXML_NOT_FOUND_ERR;
589 if (oldChild->prevSibling) {
590 oldChild->prevSibling->nextSibling = oldChild->nextSibling;
592 if (nodeptr->firstChild == oldChild) {
593 nodeptr->firstChild = oldChild->nextSibling;
595 if (oldChild->nextSibling) {
596 oldChild->nextSibling->prevSibling = oldChild->prevSibling;
598 oldChild->nextSibling = NULL;
599 oldChild->prevSibling = NULL;
600 oldChild->parentNode = NULL;
602 *returnNode = oldChild;
614 if (!nodeptr || !newChild) {
615 return IXML_INVALID_PARAMETER;
618 if (newChild->ownerDocument &&
619 nodeptr->ownerDocument != newChild->ownerDocument) {
620 return IXML_WRONG_DOCUMENT_ERR;
624 return IXML_HIERARCHY_REQUEST_ERR;
628 return IXML_HIERARCHY_REQUEST_ERR;
634 newChild->parentNode = nodeptr;
635 newChild->ownerDocument = nodeptr->ownerDocument;
637 if (!nodeptr->firstChild) {
638 nodeptr->firstChild = newChild;
640 prev = nodeptr->firstChild;
641 next = prev->nextSibling;
644 next = prev->nextSibling;
646 prev->nextSibling = newChild;
647 newChild->prevSibling = prev;
672 if (rc != IXML_SUCCESS) {
677 if (rc != IXML_SUCCESS) {
681 newNode->nodeType = eTEXT_NODE;
707 if (rc != IXML_SUCCESS) {
712 if (rc != IXML_SUCCESS) {
716 newNode->nodeType = eCDATA_SECTION_NODE;
743 if (rc != IXML_SUCCESS) {
750 if (rc != IXML_SUCCESS) {
755 if (rc != IXML_SUCCESS) {
760 if (rc != IXML_SUCCESS) {
765 if (rc != IXML_SUCCESS) {
770 if (rc != IXML_SUCCESS) {
774 elementNode->nodeType = eELEMENT_NODE;
799 if (rc != IXML_SUCCESS) {
803 newDoc->n.nodeType = eDOCUMENT_NODE;
831 if (rc != IXML_SUCCESS) {
836 if (rc != IXML_SUCCESS) {
843 if (rc != IXML_SUCCESS) {
848 if (rc != IXML_SUCCESS) {
853 if (rc != IXML_SUCCESS) {
857 attrNode->nodeType = eATTRIBUTE_NODE;
876 newAttr->specified = 1;
888 IXML_Node* parentNode = nodeptr->parentNode;
889 IXML_Node* nextptr = nodeptr->nextSibling;
892 nextptr->parentNode = parentNode;
893 nextptr = nextptr->nextSibling;
915 switch (nodeptr->nodeType) {
921 newElement->n.firstAttr =
924 newElement->n.firstChild =
926 if (newElement->n.firstChild) {
927 newElement->n.firstChild->parentNode =
933 newElement->n.nextSibling = nextSib;
935 nextSib->prevSibling = (
IXML_Node*)newElement;
940 case eATTRIBUTE_NODE:
946 newAttr->n.nextSibling = nextSib;
948 nextSib->prevSibling = (
IXML_Node*)newAttr;
955 case eCDATA_SECTION_NODE:
966 newNode->firstChild =
968 if (newNode->firstChild) {
969 newNode->firstChild->parentNode = newNode;
974 case eENTITY_REFERENCE_NODE:
976 case ePROCESSING_INSTRUCTION_NODE:
978 case eDOCUMENT_TYPE_NODE:
979 case eDOCUMENT_FRAGMENT_NODE:
1004 switch (nodeptr->nodeType) {
1010 newElement->n.firstAttr =
1013 newElement->n.firstChild =
1015 childNode = newElement->n.firstChild;
1017 childNode->parentNode = (
IXML_Node*)newElement;
1018 childNode = childNode->nextSibling;
1020 newElement->n.nextSibling = NULL;
1024 case eATTRIBUTE_NODE:
1026 case eCDATA_SECTION_NODE:
1027 case eDOCUMENT_NODE:
1031 case eENTITY_REFERENCE_NODE:
1033 case ePROCESSING_INSTRUCTION_NODE:
1035 case eDOCUMENT_TYPE_NODE:
1036 case eDOCUMENT_FRAGMENT_NODE:
1037 case eNOTATION_NODE:
1050 newNode->parentNode = NULL;
1062 switch (nodeptr->nodeType) {
1063 case eATTRIBUTE_NODE:
1088 tempNode = nodeptr->firstChild;
1091 if (rc != IXML_SUCCESS) {
1095 tempNode = tempNode->nextSibling;
1109 switch (nodeptr->nodeType) {
1111 returnNamedNodeMap =
1113 if (!returnNamedNodeMap) {
1117 tempNode = nodeptr->firstAttr;
1121 if (rc != IXML_SUCCESS) {
1125 tempNode = tempNode->nextSibling;
1127 return returnNamedNodeMap;
1139 return nodeptr->firstChild != NULL;
1144 switch (nodeptr->nodeType) {
1146 if (nodeptr->firstAttr)
1165 const char* tagname,
1173 if (strcmp(tagname, name) == 0 || strcmp(tagname,
"*") == 0) {
1188 assert(n && tagname);
1192 if (strcmp(tagname, name) == 0 || strcmp(tagname,
"*") == 0) {
1207 const char* namespaceURI,
1209 const char* localName,
1220 if (name && nsURI &&
1221 (strcmp(namespaceURI, nsURI) == 0 ||
1222 strcmp(namespaceURI,
"*") == 0) &&
1223 (strcmp(name, localName) == 0 || strcmp(localName,
"*") == 0)) {
1228 namespaceURI, localName, list);
1230 namespaceURI, localName, list);
1235 const char* localName,
1240 assert(n && namespaceURI && localName);
1245 if (name && nsURI &&
1246 (strcmp(namespaceURI, nsURI) == 0 ||
1247 strcmp(namespaceURI,
"*") == 0) &&
1248 (strcmp(name, localName) == 0 || strcmp(localName,
"*") == 0)) {
1254 namespaceURI, localName, list);
1258 int rc = IXML_SUCCESS;
1262 if (node->nodeName) {
1263 free(node->nodeName);
1264 node->nodeName = NULL;
1266 if (qualifiedName) {
1268 node->nodeName = strdup(qualifiedName);
1269 if (!node->nodeName) {
1270 return IXML_INSUFFICIENT_MEMORY;
1273 if (rc != IXML_SUCCESS) {
1274 free(node->nodeName);
1284 assert(destNode && src);
1285 if (!destNode || !src) {
1286 return IXML_INVALID_PARAMETER;
1289 if (rc != IXML_SUCCESS) {
1293 if (rc != IXML_SUCCESS) {
1297 if (rc != IXML_SUCCESS) {
1301 destNode->nodeType = src->nodeType;
1303 return IXML_SUCCESS;
1306 if (destNode->nodeName) {
1307 free(destNode->nodeName);
1308 destNode->nodeName = NULL;
1310 if (destNode->nodeValue) {
1311 free(destNode->nodeValue);
1312 destNode->nodeValue = NULL;
1314 if (destNode->localName) {
1315 free(destNode->localName);
1316 destNode->localName = NULL;
1319 return IXML_INSUFFICIENT_MEMORY;
1322#ifdef IXML_HAVE_SCRIPTSUPPORT
1323void ixmlNode_setCTag(
IXML_Node* nodeptr,
void* ctag) {
1325 nodeptr->ctag = ctag;
1329void* ixmlNode_getCTag(
IXML_Node* nodeptr) {
1331 return nodeptr->ctag;
Data structure representing a CDATA section node.
Data structure common to all types of nodes.
Data structure representing an Attribute node.
Data structure representing a list of nodes.
Data structure representing a list of named nodes.
Data structure representing an Element node.
Data structure representing the DOM Document.
IXML_Document * ixmlNode_getOwnerDocument(IXML_Node *nodeptr)
Retrieves the document object associated with this Node.
unsigned short ixmlNode_getNodeType(IXML_Node *nodeptr)
Retrieves the type of a Node. Note that not all possible return values are actually implemented.
int ixmlNode_appendChild(IXML_Node *nodeptr, IXML_Node *newChild)
Appends a child Node to the list of children of a Node.
int ixmlNode_setNodeValue(IXML_Node *nodeptr, const char *newNodeValue)
Assigns a new value to a Node.
int ixmlNode_replaceChild(IXML_Node *nodeptr, IXML_Node *newChild, IXML_Node *oldChild, IXML_Node **returnNode)
Replaces an existing child Node with a new child Node in the list of children of a Node.
PUPNP_Api void ixmlAttr_free(IXML_Attr *attrNode)
Frees an Attr node.
void ixmlCDATASection_init(IXML_CDATASection *nodeptr)
Initializes a CDATASection node.
int ixmlNode_removeChild(IXML_Node *nodeptr, IXML_Node *oldChild, IXML_Node **returnNode)
Removes a child from the list of children of a Node.
#define DOMString
The type of DOM strings.
void ixmlNode_free(IXML_Node *nodeptr)
Frees a Node and all Nodes in its subtree.
void ixmlCDATASection_free(IXML_CDATASection *nodeptr)
Frees a CDATASection node.
IXML_Node * ixmlNode_cloneNode(IXML_Node *nodeptr, int deep)
Clones a Node.
IXML_Node * ixmlNode_getNextSibling(IXML_Node *nodeptr)
Retrieves the sibling Node immediately following this Node.
PUPNP_Api void ixmlElement_init(IXML_Element *element)
Initializes a IXML_Element node.
const DOMString ixmlNode_getNodeValue(IXML_Node *nodeptr)
Returns the value of the Node as a string.
const DOMString ixmlNode_getNodeName(IXML_Node *nodeptr)
Returns the name of the Node, depending on what type of Node it is, in a read-only string.
IXML_Node * ixmlNode_getParentNode(IXML_Node *nodeptr)
Retrieves the parent Node for a Node.
PUPNP_Api void ixmlDocument_init(IXML_Document *nodeptr)
Initializes a Document node.
const DOMString ixmlNode_getLocalName(IXML_Node *nodeptr)
Retrieves the local name of a Node, if present.
IXML_NodeList * ixmlNode_getChildNodes(IXML_Node *nodeptr)
Retrieves the list of children of a Node in a NodeList structure.
int ixmlNode_insertBefore(IXML_Node *nodeptr, IXML_Node *newChild, IXML_Node *refChild)
Inserts a new child Node before the existing child Node.
IXML_Node * ixmlNode_getLastChild(IXML_Node *nodeptr)
Retrieves the last child Node of a Node.
const DOMString ixmlNode_getPrefix(IXML_Node *nodeptr)
Retrieves the namespace prefix, if present.
PUPNP_Api void ixmlNodeList_free(IXML_NodeList *nList)
Frees a NodeList object.
int ixmlNode_hasAttributes(IXML_Node *nodeptr)
Queries whether this Node has attributes.
IXML_Node * ixmlNode_getPreviousSibling(IXML_Node *nodeptr)
Retrieves the sibling Node immediately preceding this Node.
PUPNP_Api void ixmlElement_free(IXML_Element *element)
Frees the given Element and any subtree of the Element.
#define DOCUMENTNODENAME
The type of the DOM node.
const DOMString ixmlNode_getNamespaceURI(IXML_Node *nodeptr)
Retrieves the namespace URI for a Node as a DOMString.
IXML_Node * ixmlNode_getFirstChild(IXML_Node *nodeptr)
Retrieves the first child Node of a Node.
IXML_NamedNodeMap * ixmlNode_getAttributes(IXML_Node *nodeptr)
Retrieves the attributes of a Node, if it is an Element node, in a NamedNodeMap structure.
PUPNP_Api void ixmlNamedNodeMap_free(IXML_NamedNodeMap *nnMap)
Frees a NamedNodeMap.
int ixmlNode_hasChildNodes(IXML_Node *nodeptr)
Queries whether or not a Node has children.
PUPNP_Api void ixmlDocument_free(IXML_Document *doc)
Frees a Document object and all Nodes associated with it.
int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add)
Add a node to nodelist.
void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap)
Initializes a NamedNodeMap object.
void ixmlNodeList_init(IXML_NodeList *nList)
Initializes a nodelist.
int ixmlElement_setTagName(IXML_Element *element, const char *tagName)
Set the given element's tagName.
void ixmlAttr_init(IXML_Attr *attrNode)
ixmlAttr_init
int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr)
Set the node prefix and localName as defined by the nodeName in the form of ns:name.
int ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add)
Add a node to a NamedNodeMap.
static void ixmlNode_setSiblingNodesParent(IXML_Node *nodeptr)
Sets siblings nodes parent to be the same as this node's.
static int ixmlNode_setPrefix(IXML_Node *nodeptr, const char *prefix)
Set the prefix of the node.
static int ixmlNode_allowChildren(IXML_Node *nodeptr, IXML_Node *newChild)
Check to see whether nodeptr allows children of type newChild.
static IXML_CDATASection * ixmlNode_cloneCDATASect(IXML_CDATASection *nodeptr)
Return a clone of CDATASection node.
int ixmlNode_setNodeProperties(IXML_Node *destNode, IXML_Node *src)
static IXML_Node * ixmlNode_cloneTextNode(IXML_Node *nodeptr)
Returns a clone of nodeptr.
static void ixmlNode_freeSingleNode(IXML_Node *nodeptr)
Frees a node content.
static int ixmlNode_isAncestor(IXML_Node *ancestorNode, IXML_Node *toFind)
Check if ancestorNode is ancestor of toFind.
static IXML_Node * ixmlNode_cloneNodeTree(IXML_Node *nodeptr, int deep)
Function that clones a node tree of nodeptr.
static int ixmlNode_setNamespaceURI(IXML_Node *nodeptr, const char *namespaceURI)
Sets the namespace URI of the node.
static IXML_Attr * ixmlNode_cloneAttrDirect(IXML_Attr *nodeptr)
Return a clone of attribute node, with specified field set to 1.
static IXML_Document * ixmlNode_newDoc(void)
Returns a new document node.
static void ixmlNode_getElementsByTagNameNSRecursive(IXML_Node *n, const char *namespaceURI, const char *localName, IXML_NodeList **list)
ixmlNode_getElementsByTagNameNSRecursive
void ixmlNode_getElementsByTagName(IXML_Node *n, const char *tagname, IXML_NodeList **list)
Returns a nodeList of all descendant Elements with a given tagName, in the order in which they are en...
static IXML_Node * ixmlNode_cloneNodeTreeRecursive(IXML_Node *nodeptr, int deep)
Recursive function that clones a node tree of nodeptr.
static void ixmlNode_getElementsByTagNameRecursive(IXML_Node *n, const char *tagname, IXML_NodeList **list)
Recursively traverse the whole tree, search for element with the given tagname.
void ixmlNode_init(IXML_Node *nodeptr)
Intializes a node.
int ixmlNode_setNodeName(IXML_Node *node, const DOMString qualifiedName)
static int ixmlNode_isParent(IXML_Node *nodeptr, IXML_Node *toFind)
Check whether toFind is a children of nodeptr.
static IXML_Element * ixmlNode_cloneElement(IXML_Element *nodeptr)
Returns a clone of element node.
static IXML_Attr * ixmlNode_cloneAttr(IXML_Attr *nodeptr)
Returns a clone of an attribute node.
static int ixmlNode_setLocalName(IXML_Node *nodeptr, const char *localName)
Set the localName of the node.
int ixmlNode_compare(const IXML_Node *srcNode, const IXML_Node *destNode)
Compare two nodes to see whether they are the same node. Parent, sibling and children node are ignore...
void ixmlNode_getElementsByTagNameNS(IXML_Node *n, const char *namespaceURI, const char *localName, IXML_NodeList **list)
Returns a nodeList of all the descendant Elements with a given local name and namespace URI in the or...