void printNodes(IXML_Node *tmpRoot, int depth) { unsigned long i; IXML_NodeList *NodeList1; IXML_Node *ChildNode1; unsigned short NodeType; const DOMString NodeValue; const DOMString NodeName; NodeList1 = ixmlNode_getChildNodes(tmpRoot); for (i = 0; i < 100; ++i) { ChildNode1 = ixmlNodeList_item(NodeList1, i); if (ChildNode1 == NULL) { break; } printNodes(ChildNode1, depth+1); NodeType = ixmlNode_getNodeType(ChildNode1); NodeValue = ixmlNode_getNodeValue(ChildNode1); NodeName = ixmlNode_getNodeName(ChildNode1); IxmlPrintf(__FILE__, __LINE__, "printNodes", "DEPTH-%2d-IXML_Node Type %d, " "IXML_Node Name: %s, IXML_Node Value: %s\n", depth, NodeType, NodeName, NodeValue); } }
int ixmlDocument_createElementNSEx( IXML_Document *doc, const DOMString namespaceURI, const DOMString qualifiedName, IXML_Element **rtElement) { IXML_Element *newElement = NULL; int ret = IXML_SUCCESS; int line = 0; if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) { line = __LINE__; ret = IXML_INVALID_PARAMETER; goto ErrorHandler; } ret = ixmlDocument_createElementEx(doc, qualifiedName, &newElement); if (ret != IXML_SUCCESS) { line = __LINE__; goto ErrorHandler; } /* set the namespaceURI field */ newElement->n.namespaceURI = _strdup(namespaceURI); if (newElement->n.namespaceURI == NULL) { line = __LINE__; ixmlElement_free(newElement); newElement = NULL; ret = IXML_INSUFFICIENT_MEMORY; goto ErrorHandler; } /* set the localName and prefix */ ret = ixmlNode_setNodeName((IXML_Node *)newElement, qualifiedName); if (ret != IXML_SUCCESS) { line = __LINE__; ixmlElement_free(newElement); newElement = NULL; ret = IXML_INSUFFICIENT_MEMORY; goto ErrorHandler; } newElement->n.nodeValue = NULL; ErrorHandler: *rtElement = newElement; if (ret != IXML_SUCCESS) { IxmlPrintf(__FILE__, line, "ixmlDocument_createElementNSEx", "Error %d\n", ret); } return ret; }
IXML_Element *ixmlDocument_createElement( IXML_Document *doc, const DOMString tagName) { IXML_Element *newElement = NULL; int ret = IXML_SUCCESS; ret = ixmlDocument_createElementEx(doc, tagName, &newElement); if (ret != IXML_SUCCESS) { IxmlPrintf(__FILE__, __LINE__, "ixmlDocument_createElement", "Error %d\n", ret); return NULL; } return newElement; }
/*! * \brief Recursive function to print all the node in a tree. * Internal to parser only. */ static void ixmlPrintDomTreeRecursive( /*! [in] \todo documentation. */ IXML_Node *nodeptr, /*! [in] \todo documentation. */ ixml_membuf *buf) { const char *nodeName = NULL; const char *nodeValue = NULL; IXML_Node *child = NULL, *sibling = NULL; if (nodeptr != NULL) { nodeName = (const char *)ixmlNode_getNodeName(nodeptr); nodeValue = ixmlNode_getNodeValue(nodeptr); switch (ixmlNode_getNodeType(nodeptr)) { case eTEXT_NODE: copy_with_escape(buf, nodeValue); break; case eCDATA_SECTION_NODE: ixml_membuf_append_str(buf, "<![CDATA["); ixml_membuf_append_str(buf, nodeValue); ixml_membuf_append_str(buf, "]]>"); break; case ePROCESSING_INSTRUCTION_NODE: ixml_membuf_append_str(buf, "<?"); ixml_membuf_append_str(buf, nodeName); ixml_membuf_append_str(buf, " "); copy_with_escape(buf, nodeValue); ixml_membuf_append_str(buf, "?>\n"); break; case eDOCUMENT_NODE: ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild(nodeptr), buf); break; case eATTRIBUTE_NODE: ixml_membuf_append_str(buf, nodeName); ixml_membuf_append_str(buf, "=\""); copy_with_escape(buf, nodeValue); ixml_membuf_append_str(buf, "\""); if (nodeptr->nextSibling != NULL) { ixml_membuf_append_str(buf, " "); ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf); } break; case eELEMENT_NODE: ixml_membuf_append_str(buf, "<"); ixml_membuf_append_str(buf, nodeName); if (nodeptr->firstAttr != NULL) { ixml_membuf_append_str(buf, " "); ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); } child = ixmlNode_getFirstChild(nodeptr); if (child != NULL && ixmlNode_getNodeType(child) == eELEMENT_NODE) { ixml_membuf_append_str(buf, ">\r\n"); } else { ixml_membuf_append_str(buf, ">"); } // output the children ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild(nodeptr), buf); // Done with children. Output the end tag. ixml_membuf_append_str(buf, "</"); ixml_membuf_append_str(buf, nodeName); sibling = ixmlNode_getNextSibling(nodeptr); if (sibling != NULL && ixmlNode_getNodeType(sibling) == eTEXT_NODE) { ixml_membuf_append_str( buf, ">" ); } else { ixml_membuf_append_str( buf, ">\r\n" ); } ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling(nodeptr), buf); break; default: IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: " "Warning, unknown node type %d\n", __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); break; } } }