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

📄 c14n.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
    /*      * print out all elements from list      */    xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx);    /*      * Cleanup     */    xmlListDelete(list);    return (0);}/** * xmlC14NAttrsCompare: * @attr1:		the pointer tls o first attr * @attr2: 		the pointer to second attr * * Prints the given attribute to the output buffer from C14N context. * * Returns -1 if attr1 < attr2, 0 if attr1 == attr2 or 1 if attr1 > attr2. */static intxmlC14NAttrsCompare(xmlAttrPtr attr1, xmlAttrPtr attr2){    int ret = 0;    /*     * Simple cases     */    if (attr1 == attr2)        return (0);    if (attr1 == NULL)        return (-1);    if (attr2 == NULL)        return (1);    if (attr1->ns == attr2->ns) {        return (xmlStrcmp(attr1->name, attr2->name));    }    /*      * Attributes in the default namespace are first     * because the default namespace is not applied to     * unqualified attributes     */    if (attr1->ns == NULL)        return (-1);    if (attr2->ns == NULL)        return (1);    if (attr1->ns->prefix == NULL)        return (-1);    if (attr2->ns->prefix == NULL)        return (1);    ret = xmlStrcmp(attr1->ns->href, attr2->ns->href);    if (ret == 0) {        ret = xmlStrcmp(attr1->name, attr2->name);    }    return (ret);}/** * xmlC14NPrintAttrs: * @attr:		the pointer to attr * @ctx: 		the C14N context * * Prints out canonical attribute urrent node to the * buffer from C14N context as follows  * * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) * * Returns 1 on success or 0 on fail. */static intxmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx){    xmlChar *value;    xmlChar *buffer;    if ((attr == NULL) || (ctx == NULL)) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,                        "xmlC14NPrintAttrs: attr == NULL or ctx == NULL\n");#endif        return (0);    }    xmlOutputBufferWriteString(ctx->buf, " ");    if (attr->ns != NULL && xmlStrlen(attr->ns->prefix) > 0) {        xmlOutputBufferWriteString(ctx->buf,                                   (const char *) attr->ns->prefix);        xmlOutputBufferWriteString(ctx->buf, ":");    }    xmlOutputBufferWriteString(ctx->buf, (const char *) attr->name);    xmlOutputBufferWriteString(ctx->buf, "=\"");    value = xmlNodeListGetString(attr->doc, attr->children, 1);    /* todo: should we log an error if value==NULL ? */    if (value != NULL) {        buffer = xmlC11NNormalizeAttr(value);        xmlFree(value);        if (buffer != NULL) {            xmlOutputBufferWriteString(ctx->buf, (const char *) buffer);            xmlFree(buffer);        } else {#ifdef DEBUG_C14N            xmlGenericError(xmlGenericErrorContext,                            "xmlC14NPrintAttrs: xmlC11NNormalizeAttr failed\n");#endif            return (0);        }    }    xmlOutputBufferWriteString(ctx->buf, "\"");    return (1);}/** * xmlC14NProcessAttrsAxis: * @ctx: 		the C14N context * @cur:		the current node * * Prints out canonical attribute axis of the current node to the * buffer from C14N context as follows  * * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) * * Attribute Axis  * In lexicographic order (ascending), process each node that  * is in the element's attribute axis and in the node-set. *  * The processing of an element node E MUST be modified slightly  * when an XPath node-set is given as input and the element's  * parent is omitted from the node-set. * * * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) * * Canonical XML applied to a document subset requires the search of the  * ancestor nodes of each orphan element node for attributes in the xml  * namespace, such as xml:lang and xml:space. These are copied into the  * element node except if a declaration of the same attribute is already  * in the attribute axis of the element (whether or not it is included in  * the document subset). This search and copying are omitted from the  * Exclusive XML Canonicalization method. * * Returns 0 on success or -1 on fail. */static intxmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur){    xmlAttrPtr attr;    xmlListPtr list;    if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,                        "xmlC14NProcessAttrsAxis: Null context or node pointer or type != XML_ELEMENT_NODE.\n");#endif        return (-1);    }    /*     * Create a sorted list to store element attributes     */    list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NAttrsCompare);    if (list == NULL) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,                        "xmlC14NProcessAttrsAxis: list creation failed\n");#endif        return (-1);    }    /*      * Add all visible attributes from current node.      */    attr = cur->properties;    while (attr != NULL) {        /* check that attribute is visible */        if (xmlC14NIsVisible(ctx, attr, cur)) {            xmlListInsert(list, attr);        }        attr = attr->next;    }    /*      * include attributes in "xml" namespace defined in ancestors     * (only for non-exclusive XML Canonicalization)     */    if ((!ctx->exclusive) && (cur->parent != NULL)        && (!xmlC14NIsVisible(ctx, cur->parent, cur->parent->parent))) {        /*         * If XPath node-set is not specified then the parent is always          * visible!         */        cur = cur->parent;        while (cur != NULL) {            attr = cur->properties;            while (attr != NULL) {                if ((attr->ns != NULL)                    && (xmlStrEqual(attr->ns->prefix, BAD_CAST "xml"))) {                    if (xmlListSearch(list, attr) == NULL) {                        xmlListInsert(list, attr);                    }                }                attr = attr->next;            }            cur = cur->parent;        }    }    /*      * print out all elements from list      */    xmlListWalk(list, (xmlListWalker) xmlC14NPrintAttrs, (const void *) ctx);    /*      * Cleanup     */    xmlListDelete(list);    return (0);}/**  * xmlC14NCheckForRelativeNamespaces: * @ctx:		the C14N context * @cur:		the current element node * * Checks that current element node has no relative namespaces defined * * Returns 0 if the node has no relative namespaces or -1 otherwise. */static intxmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur){    xmlNsPtr ns;    if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,                        "xmlC14NCheckForRelativeNamespaces: Null context or node pointer or type != XML_ELEMENT_NODE.\n");#endif        return (-1);    }    ns = cur->nsDef;    while (ns != NULL) {        if (xmlStrlen(ns->href) > 0) {            xmlURIPtr uri;            uri = xmlParseURI((const char *) ns->href);            if (uri == NULL) {#ifdef DEBUG_C14N                xmlGenericError(xmlGenericErrorContext,                                "xmlC14NCheckForRelativeNamespaces: unable to parse uri=\"%s\".\n",                                ns->href);#endif                return (-1);            }            if (xmlStrlen((const xmlChar *) uri->scheme) == 0) {                xmlFreeURI(uri);                return (-1);            }            if ((!xmlStrEqual                 ((const xmlChar *) uri->scheme, BAD_CAST "urn"))                && (xmlStrlen((const xmlChar *) uri->server) == 0)) {                xmlFreeURI(uri);                return (-1);            }            xmlFreeURI(uri);        }        ns = ns->next;    }    return (0);}/** * xmlC14NProcessElementNode: * @ctx: 		the pointer to C14N context object * @cur:		the node to process *  		 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) * * Element Nodes * If the element is not in the node-set, then the result is obtained  * by processing the namespace axis, then the attribute axis, then  * processing the child nodes of the element that are in the node-set  * (in document order). If the element is in the node-set, then the result  * is an open angle bracket (<), the element QName, the result of  * processing the namespace axis, the result of processing the attribute  * axis, a close angle bracket (>), the result of processing the child  * nodes of the element that are in the node-set (in document order), an  * open angle bracket, a forward slash (/), the element QName, and a close  * angle bracket. * * Returns non-negative value on success or negative value on fail */static intxmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible){    int ret;    xmlC14NVisibleNsStack state;    int parent_is_doc = 0;    if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,                        "xmlC14NProcessElementNode: Null context or node pointer or type != XML_ELEMENT_NODE.\n");#endif        return (-1);    }    /*      * Check relative relative namespaces:     * implementations of XML canonicalization MUST report an operation     * failure on documents containing relative namespace URIs.     */    if (xmlC14NCheckForRelativeNamespaces(ctx, cur) < 0) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,                        "xmlC14NProcessElementNode: xmlC14NCheckForRelativeNamespaces failed.\n");#endif        return (-1);    }    /*      * Save ns_rendered stack position     */    xmlC14NVisibleNsStackSave(ctx->ns_rendered, &state);    if (visible) {	        if (ctx->parent_is_doc) {	    /* save this flag into the stack */	    parent_is_doc = ctx->parent_is_doc;	    ctx->parent_is_doc = 0;            ctx->pos = XMLC14N_INSIDE_DOCUMENT_ELEMENT;        }        xmlOutputBufferWriteString(ctx->buf, "<");        if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) {            xmlOutputBufferWriteString(ctx->buf,                                       (const char *) cur->ns->prefix);            xmlOutputBufferWriteString(ctx->buf, ":");        }        xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name);    }    if (!ctx->exclusive) {        ret = xmlC14NProcessNamespacesAxis(ctx, cur, visible);    } else {        ret = xmlExcC14NProcessNamespacesAxis(ctx, cur, visible);    }    if (ret < 0) {#ifdef DEBUG_C14N        xmlGenericError(xmlGenericErrorContext,            "xmlC14NProcessElementNode: xmlC14NProcessNamespacesAxis failed.\n");#endif        return (-1);    }    /* todo: shouldn't this go to "visible only"? */    if(visible) {	xmlC14NVisibleNsStackShift(ctx->ns_rendered);    }        if(visible) {	ret = xmlC14NProcessAttrsAxis(ctx, cur);	if (ret < 0) {#ifdef DEBUG_C14N    	    xmlGenericError(xmlGenericErrorContext,                "xmlC14NProcessElementNode: xmlC14NProcessAttrsAxis failed.\n");#endif    	    return (-1);	}    }    if (visible) {         xmlOutputBufferWriteString(ctx->buf, ">");    }    if (cur->children != NULL) {        ret = xmlC14NProcessNodeList(ctx, cur->children);        if (ret < 0) {#ifdef DEBUG_C14N            xmlGenericError(xmlGenericErrorContext,                            "xmlC14NProcessElementNode: xmlC14NProcessNodeList failed.\n");#endif            return (-1);        }    }    if (visible) {        xmlOutputBufferWriteString(ctx->buf, "</");        if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) {            xmlOutputBufferWriteString(ctx->buf,                                       (const char *) cur->ns->prefix);            xmlOutputBufferWriteString(ctx->buf, ":");

⌨️ 快捷键说明

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