⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
    xmlNodePtr cur;    if (name == NULL) {#ifdef DEBUG_TREE        xmlGenericError(xmlGenericErrorContext,		"xmlNewNode : name == NULL\n");#endif	return(NULL);    }    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building node");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ELEMENT_NODE;        cur->name = xmlStrdup(name);    cur->ns = ns;    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}/** * xmlNewNodeEatName: * @ns:  namespace if any * @name:  the node name * * Creation of a new node element. @ns is optional (NULL). * * Returns a pointer to the new node object, with pointer @name as * new node's name. Use xmlNewNode() if a copy of @name string is * is needed as new node's name. */xmlNodePtrxmlNewNodeEatName(xmlNsPtr ns, xmlChar *name) {    xmlNodePtr cur;    if (name == NULL) {#ifdef DEBUG_TREE        xmlGenericError(xmlGenericErrorContext,		"xmlNewNode : name == NULL\n");#endif	return(NULL);    }    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building node");        xmlFree(name);	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ELEMENT_NODE;        cur->name = name;    cur->ns = ns;    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue((xmlNodePtr)cur);    return(cur);}/** * xmlNewDocNode: * @doc:  the document * @ns:  namespace if any * @name:  the node name * @content:  the XML text content if any * * Creation of a new node element within a document. @ns and @content * are optional (NULL). * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities *       references, but XML special chars need to be escaped first by using *       xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't *       need entities support. * * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,              const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewNode(ns, name);    if (cur != NULL) {        cur->doc = doc;	if (content != NULL) {	    cur->children = xmlStringGetNodeList(doc, content);	    UPDATE_LAST_CHILD_AND_PARENT(cur)	}    }    return(cur);}/** * xmlNewDocNodeEatName: * @doc:  the document * @ns:  namespace if any * @name:  the node name * @content:  the XML text content if any * * Creation of a new node element within a document. @ns and @content * are optional (NULL). * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities *       references, but XML special chars need to be escaped first by using *       xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't *       need entities support. * * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocNodeEatName(xmlDocPtr doc, xmlNsPtr ns,              xmlChar *name, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewNodeEatName(ns, name);    if (cur != NULL) {        cur->doc = doc;	if (content != NULL) {	    cur->children = xmlStringGetNodeList(doc, content);	    UPDATE_LAST_CHILD_AND_PARENT(cur)	}    }    return(cur);}#ifdef LIBXML_TREE_ENABLED/** * xmlNewDocRawNode: * @doc:  the document * @ns:  namespace if any * @name:  the node name * @content:  the text content if any * * Creation of a new node element within a document. @ns and @content * are optional (NULL). * * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocRawNode(xmlDocPtr doc, xmlNsPtr ns,                 const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewNode(ns, name);    if (cur != NULL) {        cur->doc = doc;	if (content != NULL) {	    cur->children = xmlNewDocText(doc, content);	    UPDATE_LAST_CHILD_AND_PARENT(cur)	}    }    return(cur);}/** * xmlNewDocFragment: * @doc:  the document owning the fragment * * Creation of a new Fragment node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocFragment(xmlDocPtr doc) {    xmlNodePtr cur;    /*     * Allocate a new DocumentFragment node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building fragment");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_DOCUMENT_FRAG_NODE;    cur->doc = doc;    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}#endif /* LIBXML_TREE_ENABLED *//** * xmlNewText: * @content:  the text content * * Creation of a new text node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewText(const xmlChar *content) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building text");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_TEXT_NODE;    cur->name = xmlStringText;    if (content != NULL) {	cur->content = xmlStrdup(content);    }    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}#ifdef LIBXML_TREE_ENABLED/** * xmlNewTextChild: * @parent:  the parent node * @ns:  a namespace if any * @name:  the name of the child * @content:  the text content of the child if any. * * Creation of a new child element, added at the end of @parent children list. * @ns and @content parameters are optional (NULL). If @ns is NULL, the newly * created element inherits the namespace of @parent. If @content is non NULL, * a child TEXT node will be created containing the string @content. * NOTE: Use xmlNewChild() if @content will contain entities that need to be * preserved. Use this function, xmlNewTextChild(), if you need to ensure that * reserved XML chars that might appear in @content, such as the ampersand,  * greater-than or less-than signs, are automatically replaced by their XML  * escaped entity representations.  * * Returns a pointer to the new node object. */xmlNodePtrxmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns,            const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur, prev;    if (parent == NULL) {#ifdef DEBUG_TREE        xmlGenericError(xmlGenericErrorContext,		"xmlNewTextChild : parent == NULL\n");#endif	return(NULL);    }    if (name == NULL) {#ifdef DEBUG_TREE        xmlGenericError(xmlGenericErrorContext,		"xmlNewTextChild : name == NULL\n");#endif	return(NULL);    }    /*     * Allocate a new node     */    if (parent->type == XML_ELEMENT_NODE) {	if (ns == NULL)	    cur = xmlNewDocRawNode(parent->doc, parent->ns, name, content);	else	    cur = xmlNewDocRawNode(parent->doc, ns, name, content);    } else if ((parent->type == XML_DOCUMENT_NODE) ||	       (parent->type == XML_HTML_DOCUMENT_NODE)) {	if (ns == NULL)	    cur = xmlNewDocRawNode((xmlDocPtr) parent, NULL, name, content);	else	    cur = xmlNewDocRawNode((xmlDocPtr) parent, ns, name, content);    } else if (parent->type == XML_DOCUMENT_FRAG_NODE) {	    cur = xmlNewDocRawNode( parent->doc, ns, name, content);    } else {	return(NULL);    }    if (cur == NULL) return(NULL);    /*     * add the new element at the end of the children list.     */    cur->type = XML_ELEMENT_NODE;    cur->parent = parent;    cur->doc = parent->doc;    if (parent->children == NULL) {        parent->children = cur;	parent->last = cur;    } else {        prev = parent->last;	prev->next = cur;	cur->prev = prev;	parent->last = cur;    }    return(cur);}#endif /* LIBXML_TREE_ENABLED *//** * xmlNewCharRef: * @doc: the document * @name:  the char ref string, starting with # or "&# ... ;" * * Creation of a new character reference node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewCharRef(xmlDocPtr doc, const xmlChar *name) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building character reference");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ENTITY_REF_NODE;    cur->doc = doc;    if (name[0] == '&') {        int len;        name++;	len = xmlStrlen(name);	if (name[len - 1] == ';')	    cur->name = xmlStrndup(name, len - 1);	else	    cur->name = xmlStrndup(name, len);    } else	cur->name = xmlStrdup(name);    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}/** * xmlNewReference: * @doc: the document * @name:  the reference name, or the reference string with & and ; * * Creation of a new reference node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewReference(xmlDocPtr doc, const xmlChar *name) {    xmlNodePtr cur;    xmlEntityPtr ent;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building reference");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ENTITY_REF_NODE;    cur->doc = doc;    if (name[0] == '&') {        int len;        name++;	len = xmlStrlen(name);	if (name[len - 1] == ';')	    cur->name = xmlStrndup(name, len - 1);	else	    cur->name = xmlStrndup(name, len);    } else	cur->name = xmlStrdup(name);    ent = xmlGetDocEntity(doc, cur->name);    if (ent != NULL) {	cur->content = ent->content;	/*	 * The parent pointer in entity is a DTD pointer and thus is NOT	 * updated.  Not sure if this is 100% correct.	 *  -George	 */	cur->children = (xmlNodePtr) ent;	cur->last = (xmlNodePtr) ent;    }    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}/** * xmlNewDocText: * @doc: the document * @content:  the text content * * Creation of a new text node within a document. * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocText(xmlDocPtr doc, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewText(content);    if (cur != NULL) cur->doc = doc;    return(cur);}/** * xmlNewTextLen: * @content:  the text content * @len:  the text len. * * Creation of a new text node with an extra parameter for the content's length * Returns a pointer to the new node object. */xmlNodePtrxmlNewTextLen(const xmlChar *content, int len) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building text");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_TEXT_NODE;    cur->name = xmlStringText;    if (content != NULL) {	cur->content = xmlStrndup(content, len);    }    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}/** * xmlNewDocTextLen: * @doc: the document * @content:  the text content * @len:  the text len. * * Creation of a new text node with an extra content length parameter. The * text node pertain to a given document. * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocTextLen(xmlDocPtr doc, const xmlChar *content, int len) {    xmlNodePtr cur;    cur = xmlNewTextLen(content, len);    if (cur != NULL) cur->doc = doc;    return(cur);}/** * xmlNewComment: * @content:  the comment content * * Creation of a new node containing a comment. * Returns a pointer to the new node object. */xmlNodePtrxmlNewComment(const xmlChar *content) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building comment");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_COMMENT_NODE;    cur->name = xmlStringComment;    if (content != NULL) {	cur->content = xmlStrdup(content);    }    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))	xmlRegisterNodeDefaultValue(cur);    return(cur);}/** * xmlNewCDataBlock: * @doc:  the document * @content:  the CDATA block content content * @len:  the length of the block * * Creation of a new node containing a CDATA block. * Returns a pointer to the new node object. */xmlNodePtrxmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {	xmlTreeErrMemory("building CDATA");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = X

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -