当前位置: 首页>>代码示例>>C++>>正文


C++ xmlStrdup函数代码示例

本文整理汇总了C++中xmlStrdup函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlStrdup函数的具体用法?C++ xmlStrdup怎么用?C++ xmlStrdup使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xmlStrdup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rxml_default_tree_indent_string_set

/*
 * call-seq:
 *    XML.default_tree_indent_string = "string"
 *
 * Set the default string used by parsers to indent the XML tree
 * for output.
 */
static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string)
{
  Check_Type(string, T_STRING);
  xmlTreeIndentString = (const char *)xmlStrdup((xmlChar *)StringValuePtr(string));
  return (string);
}
开发者ID:xml4r,项目名称:libxml-ruby,代码行数:13,代码来源:ruby_xml.c

示例2: pgxmlNodeSetToText

static xmlChar
*
pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
				   xmlChar * toptagname,
				   xmlChar * septagname,
				   xmlChar * plainsep)
{
	/* Function translates a nodeset into a text representation */

	/*
	 * iterates over each node in the set and calls xmlNodeDump to write it to
	 * an xmlBuffer -from which an xmlChar * string is returned.
	 */

	/* each representation is surrounded by <tagname> ... </tagname> */

	/*
	 * plainsep is an ordinary (not tag) seperator - if used, then nodes are
	 * cast to string as output method
	 */


	xmlBufferPtr buf;
	xmlChar    *result;
	int			i;

	buf = xmlBufferCreate();

	if ((toptagname != NULL) && (xmlStrlen(toptagname) > 0))
	{
		xmlBufferWriteChar(buf, "<");
		xmlBufferWriteCHAR(buf, toptagname);
		xmlBufferWriteChar(buf, ">");
	}
	if (nodeset != NULL)
	{
		for (i = 0; i < nodeset->nodeNr; i++)
		{

			if (plainsep != NULL)
			{
				xmlBufferWriteCHAR(buf,
							  xmlXPathCastNodeToString(nodeset->nodeTab[i]));

				/* If this isn't the last entry, write the plain sep. */
				if (i < (nodeset->nodeNr) - 1)
					xmlBufferWriteChar(buf, plainsep);
			}
			else
			{


				if ((septagname != NULL) && (xmlStrlen(septagname) > 0))
				{
					xmlBufferWriteChar(buf, "<");
					xmlBufferWriteCHAR(buf, septagname);
					xmlBufferWriteChar(buf, ">");
				}
				xmlNodeDump(buf,
							nodeset->nodeTab[i]->doc,
							nodeset->nodeTab[i],
							1, 0);

				if ((septagname != NULL) && (xmlStrlen(septagname) > 0))
				{
					xmlBufferWriteChar(buf, "</");
					xmlBufferWriteCHAR(buf, septagname);
					xmlBufferWriteChar(buf, ">");
				}
			}
		}
	}

	if ((toptagname != NULL) && (xmlStrlen(toptagname) > 0))
	{
		xmlBufferWriteChar(buf, "</");
		xmlBufferWriteCHAR(buf, toptagname);
		xmlBufferWriteChar(buf, ">");
	}
	result = xmlStrdup(buf->content);
	xmlBufferFree(buf);
	return result;
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:83,代码来源:xpath.c

示例3: xsltprocExternalEntityLoader

/* This snippet is borrowed from the xsltproc source
 * and adapted to help the xsl transform find our temporary
 * files in $HOME/.gnc-migration-tmp/
 */
static xmlParserInputPtr
xsltprocExternalEntityLoader(const char *URL, const char *ID,
                             xmlParserCtxtPtr ctxt)
{
    xmlParserInputPtr ret;
    warningSAXFunc warning = NULL;
    xmlChar *newURL;
    gchar *tmpdir = g_build_filename (g_get_home_dir (), ".gnc-migration-tmp", NULL);

    const char *lastsegment = URL;
    const char *iter = URL;

    while (*iter != 0)
    {
        if (*iter == '/')
            lastsegment = iter + 1;
        iter++;
    }

    if ((ctxt != NULL) && (ctxt->sax != NULL))
    {
        warning = ctxt->sax->warning;
        ctxt->sax->warning = NULL;
    }

    if (defaultEntityLoader != NULL)
    {
        ret = defaultEntityLoader(URL, ID, ctxt);
        if (ret != NULL)
        {
            if (warning != NULL)
                ctxt->sax->warning = warning;
            return(ret);
        }
    }

    newURL = xmlStrdup((const xmlChar *) tmpdir);
    newURL = xmlStrcat(newURL, (const xmlChar *) "/");
    newURL = xmlStrcat(newURL, (const xmlChar *) lastsegment);
    g_free (tmpdir);
    if (newURL != NULL)
    {
        ret = defaultEntityLoader((const char *)newURL, ID, ctxt);
        if (ret != NULL)
        {
            if (warning != NULL)
                ctxt->sax->warning = warning;
            xmlFree(newURL);
            return(ret);
        }
        xmlFree(newURL);
    }
    if (warning != NULL)
    {
        ctxt->sax->warning = warning;
        if (URL != NULL)
            DEBUG ("External entity \"%s\" not loaded", URL);
        else if (ID != NULL)
            DEBUG ("External entity \"%s\" not loaded", ID);
    }
    return(NULL);
}
开发者ID:jralls,项目名称:gnucash,代码行数:66,代码来源:gnc-gsettings.c

示例4: dom_xpath_ext_function_php

static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
{
	zval retval;
	int result, i;
	int error = 0;
	zend_fcall_info fci;
	xmlXPathObjectPtr obj;
	char *str;
	zend_string *callable = NULL;
	dom_xpath_object *intern;


	if (! zend_is_executing()) {
		xmlGenericError(xmlGenericErrorContext,
		"xmlExtFunctionTest: Function called from outside of PHP\n");
		error = 1;
	} else {
		intern = (dom_xpath_object *) ctxt->context->userData;
		if (intern == NULL) {
			xmlGenericError(xmlGenericErrorContext,
			"xmlExtFunctionTest: failed to get the internal object\n");
			error = 1;
		}
		else if (intern->registerPhpFunctions == 0) {
			xmlGenericError(xmlGenericErrorContext,
			"xmlExtFunctionTest: PHP Object did not register PHP functions\n");
			error = 1;
		}
	}

	if (error == 1) {
		for (i = nargs - 1; i >= 0; i--) {
			obj = valuePop(ctxt);
			xmlXPathFreeObject(obj);
		}
		return;
	}

	fci.param_count = nargs - 1;
	if (fci.param_count > 0) {
		fci.params = safe_emalloc(fci.param_count, sizeof(zval), 0);
	}
	/* Reverse order to pop values off ctxt stack */
	for (i = nargs - 2; i >= 0; i--) {
		obj = valuePop(ctxt);
		switch (obj->type) {
			case XPATH_STRING:
				ZVAL_STRING(&fci.params[i],  (char *)obj->stringval);
				break;
			case XPATH_BOOLEAN:
				ZVAL_BOOL(&fci.params[i],  obj->boolval);
				break;
			case XPATH_NUMBER:
				ZVAL_DOUBLE(&fci.params[i], obj->floatval);
				break;
			case XPATH_NODESET:
				if (type == 1) {
					str = (char *)xmlXPathCastToString(obj);
					ZVAL_STRING(&fci.params[i], str);
					xmlFree(str);
				} else if (type == 2) {
					int j;
					array_init(&fci.params[i]);
					if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
						for (j = 0; j < obj->nodesetval->nodeNr; j++) {
							xmlNodePtr node = obj->nodesetval->nodeTab[j];
							zval child;
							/* not sure, if we need this... it's copied from xpath.c */
							if (node->type == XML_NAMESPACE_DECL) {
								xmlNsPtr curns;
								xmlNodePtr nsparent;

								nsparent = node->_private;
								curns = xmlNewNs(NULL, node->name, NULL);
								if (node->children) {
									curns->prefix = xmlStrdup((xmlChar *) node->children);
								}
								if (node->children) {
									node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
								} else {
									node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
								}
								node->type = XML_NAMESPACE_DECL;
								node->parent = nsparent;
								node->ns = curns;
							}
							php_dom_create_object(node, &child, &intern->dom);
							add_next_index_zval(&fci.params[i], &child);
						}
					}
				}
				break;
			default:
			ZVAL_STRING(&fci.params[i], (char *)xmlXPathCastToString(obj));
		}
		xmlXPathFreeObject(obj);
	}

	fci.size = sizeof(fci);

//.........这里部分代码省略.........
开发者ID:AxiosCros,项目名称:php-src,代码行数:101,代码来源:xpath.c

示例5: xmlEncodeEntitiesReentrant


//.........这里部分代码省略.........
        *out++ = 'a';
        *out++ = 'm';
        *out++ = 'p';
        *out++ = ';';
    } else if (((*cur >= 0x20) && (*cur < 0x80)) ||
        (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) {
        /*
         * default case, just copy !
         */
        *out++ = *cur;
    } else if (*cur >= 0x80) {
        if (((doc != NULL) && (doc->encoding != NULL)) || (html)) {
        /*
         * Bj?rn Reese <[email protected]> provided the patch
            xmlChar xc;
            xc = (*cur & 0x3F) << 6;
            if (cur[1] != 0) {
            xc += *(++cur) & 0x3F;
            *out++ = xc;
            } else
         */
            *out++ = *cur;
        } else {
        /*
         * We assume we have UTF-8 input.
         */
        char buf[11], *ptr;
        // TODO: rename 'l' variable -- hard to understand and error-prone otherwise (looks like '1')
        int val = 0, l = 1;

        if (*cur < 0xC0) {
            xmlGenericError(xmlGenericErrorContext, EMBED_ERRTXT("xmlEncodeEntitiesReentrant : input not UTF-8\n"));
            if (doc != NULL){
                doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
                if(OOM_FLAG)
                    goto OOM;
            }
            // TODO: Detect OOM..
            // TODO: these several lines repeat four times in WHILE loop -- try to combine and use GOTO
            snprintf(buf, sizeof(buf), "&#%d;", *cur);
            buf[sizeof(buf) - 1] = 0;
            ptr = buf;
            while (*ptr != 0)
            {
                *out++ = *ptr++;
            }
            cur++;
            continue;
            // ENDTODO:
        } else if (*cur < 0xE0) {
                val = (cur[0]) & 0x1F;
                val <<= 6;
                val |= (cur[1]) & 0x3F;
                l = 2;
        } else if (*cur < 0xF0) {
                val = (cur[0]) & 0x0F;
                val <<= 6;
                val |= (cur[1]) & 0x3F;
                val <<= 6;
                val |= (cur[2]) & 0x3F;
                l = 3;
        } else if (*cur < 0xF8) {
                val = (cur[0]) & 0x07;
                val <<= 6;
                val |= (cur[1]) & 0x3F;
                val <<= 6;
开发者ID:cdaffara,项目名称:symbiandump-mw4,代码行数:67,代码来源:Libxml2_entities.c

示例6: xsltAttrListTemplateProcess


//.........这里部分代码省略.........
	if (attr->ns != origNs) {
	    origNs = attr->ns;
	    if (attr->ns != NULL) {
#ifdef XSLT_REFACTORED
		copyNs = xsltGetSpecialNamespace(ctxt, attr->parent,
		    attr->ns->href, attr->ns->prefix, target);
#else
		copyNs = xsltGetNamespace(ctxt, attr->parent,
		    attr->ns, target);
#endif
		if (copyNs == NULL)
		    goto error;
	    } else
		copyNs = NULL;
	}
	copy->ns = copyNs;

	/*
	* Set the value.
	*/
	text = xmlNewText(NULL);
	if (text != NULL) {
	    copy->last = copy->children = text;
	    text->parent = (xmlNodePtr) copy;
	    text->doc = copy->doc;

	    if (attr->psvi != NULL) {
		/*
		* Evaluate the Attribute Value Template.
		*/
		valueAVT = xsltEvalAVT(ctxt, attr->psvi, attr->parent);
		if (valueAVT == NULL) {
		    /*
		    * TODO: Damn, we need an easy mechanism to report
		    * qualified names!
		    */
		    if (attr->ns) {
			xsltTransformError(ctxt, NULL, attr->parent,
			    "Internal error: Failed to evaluate the AVT "
			    "of attribute '{%s}%s'.\n",
			    attr->ns->href, attr->name);
		    } else {
			xsltTransformError(ctxt, NULL, attr->parent,
			    "Internal error: Failed to evaluate the AVT "
			    "of attribute '%s'.\n",
			    attr->name);
		    }
		    text->content = xmlStrdup(BAD_CAST "");
		    goto error;
		} else {
		    text->content = valueAVT;
		}
	    } else if ((ctxt->internalized) &&
		(target->doc != NULL) &&
		(target->doc->dict == ctxt->dict))
	    {
		text->content = (xmlChar *) value;
	    } else {
		text->content = xmlStrdup(value);
	    }
            if ((copy != NULL) && (text != NULL) &&
                (xmlIsID(copy->doc, copy->parent, copy)))
                xmlAddID(NULL, copy->doc, text->content, copy);
	}

next_attribute:
	attr = attr->next;
    } while (attr != NULL);

    /*
    * Apply attribute-sets.
    * The creation of such attributes will not overwrite any existing
    * attribute.
    */
    attr = attrs;
    do {
#ifdef XSLT_REFACTORED
	if ((attr->psvi == xsltXSLTAttrMarker) &&
	    xmlStrEqual(attr->name, (const xmlChar *)"use-attribute-sets"))
	{
	    xsltApplyAttributeSet(ctxt, ctxt->node, (xmlNodePtr) attr, NULL);
	}
#else
	if ((attr->ns != NULL) &&
	    xmlStrEqual(attr->name, (const xmlChar *)"use-attribute-sets") &&
	    xmlStrEqual(attr->ns->href, XSLT_NAMESPACE))
	{
	    xsltApplyAttributeSet(ctxt, ctxt->node, (xmlNodePtr) attr, NULL);
	}
#endif
	attr = attr->next;
    } while (attr != NULL);

    ctxt->insert = oldInsert;
    return(target->properties);

error:
    ctxt->insert = oldInsert;
    return(NULL);
}
开发者ID:1065672644894730302,项目名称:Chromium,代码行数:101,代码来源:templates.c

示例7: get_xml_element

/* dept -1 causes depth to be ignored */
static xmlChar* get_xml_element (
    xmlTextReaderPtr reader
    )
{
    int rc;
    while((rc = xmlTextReaderRead(reader)) == 1){
        int type;
        xmlChar *name;
        type = xmlTextReaderNodeType(reader);
        if (type == XML_READER_TYPE_TEXT){
            xmlChar *value;
            value = xmlTextReaderValue(reader);
            rrd_set_error("line %d: expected element but found text '%s'",
                          xmlTextReaderGetParserLineNumber(reader),value);
            xmlFree(value);
            return NULL;
        }
        /* skip all other non-elements */
        if (type != XML_READER_TYPE_ELEMENT && type != XML_READER_TYPE_END_ELEMENT)
            continue;

        name = xmlTextReaderName(reader);
        if (type == XML_READER_TYPE_END_ELEMENT){
            xmlChar *temp;
            xmlChar *temp2;            
            temp = (xmlChar*)sprintf_alloc("/%s",name);
            temp2 = xmlStrdup(temp);
            free(temp);
            xmlFree(name);            
            return temp2;            
        }
        /* all seems well, return the happy news */
        return name;
    }
    if (rc == 0) {
	rrd_set_error("the xml ended while we were looking for an element");
    } else {
	xmlErrorPtr err = xmlGetLastError();
	/* argh: err->message often contains \n at the end. This is not 
	   what we want: Bite the bullet by copying the message, replacing any 
	   \n, constructing the rrd error message and freeing the temp. buffer.
	*/
	char *msgcpy = NULL, *c;
	if (err != NULL && err->message != NULL) {
	    msgcpy = strdup(err->message);
	    if (msgcpy != NULL) {
		for (c = msgcpy ; *c ; c++) {
		    if (*c == '\n') *c = ' ';
		}
		/* strip whitespace from end of message */
		for (c-- ; c != msgcpy ; c--) {
		    if (!isprint(*c)) {
			*c = 0;
		    }
		}
	    } else {
		/* out of memory during error handling, hmmmm */
	    }
	}

	rrd_set_error("error reading/parsing XML: %s", 
		      msgcpy != NULL ? msgcpy : "?");
	if (msgcpy) free(msgcpy);
    }
    return NULL;
} /* get_xml_element */
开发者ID:oetiker,项目名称:rrdtool-1.x,代码行数:67,代码来源:rrd_restore.c

示例8: xsltAttrTemplateProcess

/**
 * xsltAttrTemplateProcess:
 * @ctxt:  the XSLT transformation context
 * @target:  the result node
 * @cur:  the attribute template node
 *
 * Process the given attribute and return the new processed copy.
 *
 * Returns the attribute replacement.
 */
xmlAttrPtr
xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target,
	                xmlAttrPtr cur) {
    const xmlChar *value;
    xmlNsPtr ns;
    xmlAttrPtr ret;
    if ((ctxt == NULL) || (cur == NULL) || (target == NULL))
	return(NULL);
    
    if (cur->type != XML_ATTRIBUTE_NODE)
	return(NULL);

    if ((cur->children == NULL) || (cur->children->type != XML_TEXT_NODE) ||
        (cur->children->next != NULL)) {
	xsltTransformError(ctxt, NULL, cur->parent,
		"attribute %s content problem\n", cur->name);
        return(NULL);
    }
    value = cur->children->content;
    if (value == NULL)
        value = xmlDictLookup(ctxt->dict, BAD_CAST "", 0);
    if ((cur->ns != NULL) &&
	(xmlStrEqual(cur->ns->href, XSLT_NAMESPACE))) {
	if (xmlStrEqual(cur->name, (const xmlChar *)"use-attribute-sets")) {
	    xsltApplyAttributeSet(ctxt, ctxt->node, NULL, value);
	}
	return(NULL);
    }

    ret = target->properties;
    while (ret != NULL) {
        if (xmlStrEqual(ret->name, cur->name)) {
	    if (cur->ns == NULL) {
	        if (ret->ns == NULL)
		    break;
	    } else {
	        if ((ret->ns != NULL) &&
		    (xmlStrEqual(ret->ns->href, cur->ns->href)))
		    break;
	    }
	}
        ret = ret->next;
    }
    if (ret != NULL) {
        /* free the existing value */
	xmlFreeNodeList(ret->children);
	ret->children = ret->last = NULL;
    } else {
        /* create a new attribute */
	if (cur->ns != NULL)
	    ns = xsltGetPlainNamespace(ctxt, cur->parent, cur->ns, target);
	else
	    ns = NULL;
	ret = xmlNewNsProp(target, ns, cur->name, NULL);
    }
    if (ret != NULL) {
        xmlNodePtr text;

        text = xmlNewText(NULL);
	if (text != NULL) {
	    ret->last = ret->children = text;
	    text->parent = (xmlNodePtr) ret;
	    text->doc = ret->doc;
	    if (cur->psvi != NULL) {
		xmlChar *val;
		val = xsltEvalAVT(ctxt, cur->psvi, cur->parent);
		if (val == NULL) {
		    text->content = xmlStrdup(BAD_CAST "runtime error");
		} else {
		    text->content = val;
		}
	    } else if ((ctxt->internalized) && (target != NULL) &&
	               (target->doc != NULL) &&
		       (target->doc->dict == ctxt->dict)) {
		text->content = (xmlChar *) value;
	    } else {
		text->content = xmlStrdup(value);
	    }
	}
    } else {
	xsltTransformError(ctxt, NULL, cur->parent,
		"Failed to create attribute %s\n", cur->name);
    }
    return(ret);
}
开发者ID:flaithbheartaigh,项目名称:jaikuengine-mobile-frontend,代码行数:95,代码来源:templates.c

示例9: atom10_parse_link

/* Note: this function is called for both item and feed context */
static gchar *
atom10_parse_link (xmlNodePtr cur, feedParserCtxtPtr ctxt, struct atom10ParserState *state)
{
	gchar *href, *alternate = NULL;
	
	href = xml_get_ns_attribute (cur, "href", NULL);
	if (href) {
		xmlChar *baseURL = xmlNodeGetBase (cur->doc, cur);
		gchar *url, *relation, *type, *escTitle = NULL, *title;
		const gchar *feedURL = subscription_get_homepage (ctxt->subscription);
		
		if (!baseURL && feedURL && feedURL[0] != '|' && strstr (feedURL, "://"))
			baseURL = xmlStrdup (BAD_CAST (feedURL));
		url = (gchar *)common_build_url (href, (gchar *)baseURL);

		type = xml_get_ns_attribute (cur, "type", NULL);
		relation = xml_get_ns_attribute (cur, "rel", NULL);
		title = xml_get_ns_attribute (cur, "title", NULL);
		if (title)
			escTitle = g_markup_escape_text (title, -1);
		
		if (!xmlHasNsProp (cur, BAD_CAST"rel", NULL) || !relation || g_str_equal (relation, BAD_CAST"alternate"))
			alternate = g_strdup (url);
		else if (g_str_equal (relation, "replies")) {
			if (!type || g_str_equal (type, BAD_CAST"application/atom+xml")) {
				gchar *commentUri = (gchar *)common_build_url ((gchar *)url, subscription_get_homepage (ctxt->subscription));
				if (ctxt->item)
					metadata_list_set (&ctxt->item->metadata, "commentFeedUri", commentUri);
				g_free (commentUri);
			}
		} else if (g_str_equal (relation, "enclosure")) {
			if (ctxt->item) {
				gsize length = 0;
				gchar *lengthStr = xml_get_ns_attribute (cur, "length", NULL);
				if (lengthStr)
					length = atol (lengthStr);
				g_free (lengthStr);
				
				gchar *encStr = enclosure_values_to_string (url, type, length, FALSE /* not yet downloaded */);
				ctxt->item->metadata = metadata_list_append (ctxt->item->metadata, "enclosure", encStr);
				ctxt->item->hasEnclosure = TRUE;
				g_free (encStr);
			}
		} else if (g_str_equal (relation, "related") || g_str_equal (relation, "via")) {	
			if (ctxt->item)
				ctxt->item->metadata = metadata_list_append (ctxt->item->metadata, relation, url);
		} else {
			/* g_warning ("Unhandled Atom link with unexpected relation \"%s\"\n", relation); */
		}
		xmlFree (title);
		xmlFree (baseURL);
		g_free (escTitle);
		g_free (url);
		g_free(relation);
		g_free(type);
		g_free(href);
	} else {
		/* FIXME: @href is required, this document is not valid Atom */;
	}
	
	return alternate;
}
开发者ID:arteymix,项目名称:liferea,代码行数:63,代码来源:atom10.c

示例10: pgxmlNodeSetToText

/*
 * Function translates a nodeset into a text representation
 *
 * iterates over each node in the set and calls xmlNodeDump to write it to
 * an xmlBuffer -from which an xmlChar * string is returned.
 *
 * each representation is surrounded by <tagname> ... </tagname>
 *
 * plainsep is an ordinary (not tag) separator - if used, then nodes are
 * cast to string as output method
 */
static xmlChar *
pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
				   xmlChar *toptagname,
				   xmlChar *septagname,
				   xmlChar *plainsep)
{
	xmlBufferPtr buf;
	xmlChar    *result;
	int			i;

	buf = xmlBufferCreate();

	if ((toptagname != NULL) && (xmlStrlen(toptagname) > 0))
	{
		xmlBufferWriteChar(buf, "<");
		xmlBufferWriteCHAR(buf, toptagname);
		xmlBufferWriteChar(buf, ">");
	}
	if (nodeset != NULL)
	{
		for (i = 0; i < nodeset->nodeNr; i++)
		{
			if (plainsep != NULL)
			{
				xmlBufferWriteCHAR(buf,
							  xmlXPathCastNodeToString(nodeset->nodeTab[i]));

				/* If this isn't the last entry, write the plain sep. */
				if (i < (nodeset->nodeNr) - 1)
					xmlBufferWriteChar(buf, (char *) plainsep);
			}
			else
			{
				if ((septagname != NULL) && (xmlStrlen(septagname) > 0))
				{
					xmlBufferWriteChar(buf, "<");
					xmlBufferWriteCHAR(buf, septagname);
					xmlBufferWriteChar(buf, ">");
				}
				xmlNodeDump(buf,
							nodeset->nodeTab[i]->doc,
							nodeset->nodeTab[i],
							1, 0);

				if ((septagname != NULL) && (xmlStrlen(septagname) > 0))
				{
					xmlBufferWriteChar(buf, "</");
					xmlBufferWriteCHAR(buf, septagname);
					xmlBufferWriteChar(buf, ">");
				}
			}
		}
	}

	if ((toptagname != NULL) && (xmlStrlen(toptagname) > 0))
	{
		xmlBufferWriteChar(buf, "</");
		xmlBufferWriteCHAR(buf, toptagname);
		xmlBufferWriteChar(buf, ">");
	}
	result = xmlStrdup(buf->content);
	xmlBufferFree(buf);
	return result;
}
开发者ID:BioBD,项目名称:Hypothetical_Indexes,代码行数:75,代码来源:xpath.c

示例11: dom_xpath_ext_function_php

static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
{
	zval **args = NULL;
	zval *retval;
	int result, i, ret;
	int error = 0;
	zend_fcall_info fci;
	zval handler;
	xmlXPathObjectPtr obj;
	char *str;
	char *callable = NULL;
	dom_xpath_object *intern;
	
	TSRMLS_FETCH();

	if (! zend_is_executing(TSRMLS_C)) {
		xmlGenericError(xmlGenericErrorContext,
		"xmlExtFunctionTest: Function called from outside of PHP\n");
		error = 1;
	} else {
		intern = (dom_xpath_object *) ctxt->context->userData;
		if (intern == NULL) {
			xmlGenericError(xmlGenericErrorContext,
			"xmlExtFunctionTest: failed to get the internal object\n");
			error = 1;
		}
		else if (intern->registerPhpFunctions == 0) {
			xmlGenericError(xmlGenericErrorContext,
			"xmlExtFunctionTest: PHP Object did not register PHP functions\n");
			error = 1;
		}
	}
	
	if (error == 1) {
		for (i = nargs - 1; i >= 0; i--) {
			obj = valuePop(ctxt);
			xmlXPathFreeObject(obj);
		}
		return;
	}
		
	fci.param_count = nargs - 1;
	if (fci.param_count > 0) {
		fci.params = safe_emalloc(fci.param_count, sizeof(zval**), 0);
		args = safe_emalloc(fci.param_count, sizeof(zval *), 0);
	}
	/* Reverse order to pop values off ctxt stack */
	for (i = nargs - 2; i >= 0; i--) {
		obj = valuePop(ctxt);
		MAKE_STD_ZVAL(args[i]);
		switch (obj->type) {
			case XPATH_STRING:
				ZVAL_STRING(args[i],  (char *)obj->stringval, 1);
				break;
			case XPATH_BOOLEAN:
				ZVAL_BOOL(args[i],  obj->boolval);
				break;
			case XPATH_NUMBER:
				ZVAL_DOUBLE(args[i], obj->floatval);
				break;
			case XPATH_NODESET:
				if (type == 1) {
					str = (char *)xmlXPathCastToString(obj);
					ZVAL_STRING(args[i], str, 1);
					xmlFree(str);
				} else if (type == 2) {
					int j;
					array_init(args[i]);
					if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
						for (j = 0; j < obj->nodesetval->nodeNr; j++) {
							xmlNodePtr node = obj->nodesetval->nodeTab[j];
							zval *child;
							MAKE_STD_ZVAL(child);
							/* not sure, if we need this... it's copied from xpath.c */
							if (node->type == XML_NAMESPACE_DECL) {
								xmlNsPtr curns;
								xmlNodePtr nsparent;
								
								nsparent = node->_private;
								curns = xmlNewNs(NULL, node->name, NULL);
								if (node->children) {
									curns->prefix = xmlStrdup((xmlChar *) node->children);
								}
								if (node->children) {
									node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
								} else {
									node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
								}
								node->type = XML_NAMESPACE_DECL;
								node->parent = nsparent;
								node->ns = curns;
							}
							child = php_dom_create_object(node, &ret, child, (dom_object *)intern TSRMLS_CC);
							add_next_index_zval(args[i], child);
						}
					}
				}
				break;
			default:
			ZVAL_STRING(args[i], (char *)xmlXPathCastToString(obj), 1);
//.........这里部分代码省略.........
开发者ID:AzerTyQsdF,项目名称:osx,代码行数:101,代码来源:xpath.c

示例12: method_caller

static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
{
    const xmlChar * function;
    const xmlChar * functionURI;
    int i;
    size_t count;

    xsltTransformContextPtr transform;
    xmlXPathObjectPtr xpath;
    VALUE obj;
    VALUE *args;

    transform = xsltXPathGetTransformContext(ctxt);

    function = ctxt->context->function;
    functionURI = ctxt->context->functionURI;
    obj = (VALUE)xsltGetExtData(transform, functionURI);

    count = (size_t)ctxt->valueNr;
    args = calloc(count, sizeof(VALUE *));

    for(i = 0; i < count; i++) {
	VALUE thing;

	xpath = valuePop(ctxt);
	switch(xpath->type) {
	    case XPATH_STRING:
		thing = NOKOGIRI_STR_NEW2(xpath->stringval);
		break;
	    case XPATH_NODESET:
		if(NULL == xpath->nodesetval) {
		    thing = Nokogiri_wrap_xml_node_set(
			    xmlXPathNodeSetCreate(NULL),
			    DOC_RUBY_OBJECT(ctxt->context->doc));
		} else {
		    thing = Nokogiri_wrap_xml_node_set(xpath->nodesetval,
			    DOC_RUBY_OBJECT(ctxt->context->doc));
		}
		break;
	    default:
		rb_raise(rb_eRuntimeError, "do not handle type: %d", xpath->type);
	}
	args[i] = thing;
    }
    VALUE result = rb_funcall3(obj, rb_intern((const char *)function), (int)count, args);
    switch(TYPE(result)) {
	case T_FLOAT:
	case T_BIGNUM:
	case T_FIXNUM:
	    xmlXPathReturnNumber(ctxt, NUM2DBL(result));
	    break;
	case T_STRING:
	    xmlXPathReturnString(
		    ctxt,
		    xmlStrdup((xmlChar *)StringValuePtr(result))
		    );
	    break;
	case T_TRUE:
	    xmlXPathReturnTrue(ctxt);
	    break;
	case T_FALSE:
	    xmlXPathReturnFalse(ctxt);
	    break;
	case T_NIL:
	    break;
	default:
	    rb_raise(rb_eRuntimeError, "Invalid return type");
    }
}
开发者ID:chriseppstein,项目名称:nokogiri,代码行数:69,代码来源:xslt_stylesheet.c

示例13: parse_outline2

/* if p is NULL, just returns n */
int parse_outline2(xmlAttr *data, point2d32f *p, int *n, int nmax)
{
	char *str;
	char *tok;
	float x,y;
	float initx,inity;	/* beginning of sub-path */
	float curx,cury;	/* cursor */
	int i;
	int absolute;		/* absolute or relative coordinates */
	int mode;			/* 0:moveto 1:lineto */
	
	mode=-1;
	
	/* first, copy string */
	str = (char *)xmlStrdup(data->children->content);
	
	/* now, tokenize it */
	/* to avoid a lot of headaches, we make the assumption that the
	 * input will be "m blablablabala z" */
	
	absolute=0;
	/* initialize strtok */
	tok = strtok(str," ");

	curx = 0;
	cury = 0;
	
	/* just a guess (also stops gcc's whining) */
	initx = curx;
	inity = cury;
	
	i=0;
	while(tok!=NULL){
		if(strlen(tok)==1){	/* command */
			
			absolute = tok[0] > 'Z' ? 0 : 1;
			
			switch(tok[0]){
				case 'm':
				case 'M':
					mode=0;
					break;
					
				case 'l':
				case 'L':
					mode=1;
					break;
					
				case 'z':
				case 'Z':
					curx = initx;
					cury = inity;
					*n = i;
					return 0;
				
				default:
					printf("Error: command '%c' not supported.\n", tok[0]);
					printf("Cell outlines must be polygons (not curves)\n");
					return -3;
			}
		} else {	/* coordinates */
		
			sscanf(tok,"%f,%f",&x,&y);
		
			if(mode==-1){
				printf("Error: first token in path data must be command.\n");
				return -1;
			}
			
			if(mode==0){
				if(i>0){
					printf("Error: Cell outlines must be contiguous.\n");
					return -2;
				}
			}
			
			if(!absolute){x += curx; y += cury;}
			
			if(i==0){
				initx = x;	/* needed for closepath, */
				inity = y;	/* as it must move cursor to beginning */
			}
			
			if(p){
				p[i].x = x;
				p[i].y = y;
			}
			i++;
			
			curx = x;
			cury = y;
			
			if(mode==0) /* moveto can only be for first pair */
				mode=1;
		}
		
		tok = strtok(NULL," ");
	}

//.........这里部分代码省略.........
开发者ID:anj1,项目名称:cdac,代码行数:101,代码来源:svg2.c

示例14: filter_option_xml_create

static void
filter_option_xml_create (EFilterElement *element,
                          xmlNodePtr node)
{
	EFilterOption *option = E_FILTER_OPTION (element);
	xmlNodePtr n, work;

	/* Chain up to parent's xml_create() method. */
	E_FILTER_ELEMENT_CLASS (e_filter_option_parent_class)->
		xml_create (element, node);

	n = node->children;
	while (n) {
		if (!strcmp ((gchar *) n->name, "option")) {
			gchar *tmp, *value, *title = NULL, *code = NULL, *code_gen_func = NULL;

			value = (gchar *) xmlGetProp (n, (xmlChar *)"value");
			work = n->children;
			while (work) {
				if (!strcmp ((gchar *) work->name, "title") ||
					!strcmp ((gchar *) work->name, "_title")) {
					if (!title) {
						if (!(tmp = (gchar *) xmlNodeGetContent (work)))
							tmp = (gchar *) xmlStrdup ((xmlChar *)"");

						title = g_strdup (tmp);
						xmlFree (tmp);
					}
				} else if (!strcmp ((gchar *) work->name, "code")) {
					if (code || code_gen_func) {
						g_warning (
							"Element 'code' defined twice in '%s'",
							element->name);
					} else {
						xmlChar *fn;

						/* if element 'code' has attribute 'func', then
						 * the content of the element is ignored and only
						 * the 'func' is used to generate actual rule code;
						 * The function prototype is:
						 * void code_gen_func (EFilterElement *element, GString *out, EFilterPart *part);
						 * where @element is the one on which was called,
						 * @out is GString where to add the code, and
						 * @part is part which contains @element and other options of it.
						*/
						fn = xmlGetProp (work, (xmlChar *)"func");
						if (fn && *fn) {
							code_gen_func = g_strdup ((const gchar *) fn);
						} else {
							if (!(tmp = (gchar *) xmlNodeGetContent (work)))
								tmp = (gchar *) xmlStrdup ((xmlChar *)"");

							code = g_strdup (tmp);
							xmlFree (tmp);
						}

						xmlFree (fn);
					}
				}
				work = work->next;
			}

			e_filter_option_add (option, value, title, code, code_gen_func, FALSE);
			xmlFree (value);
			g_free (title);
			g_free (code);
			g_free (code_gen_func);
		} else if (g_str_equal ((gchar *) n->name, "dynamic")) {
			if (option->dynamic_func) {
				g_warning (
					"Only one 'dynamic' node is "
					"acceptable in the optionlist '%s'",
					element->name);
			} else {
				/* Expecting only one <dynamic func="cb" />
				 * in the option list,
				 * The 'cb' should be of this prototype:
				 * GSList *cb (void);
				 * returning GSList of struct _filter_option,
				 * all newly allocated, because it'll be
				 * freed with g_free and g_slist_free.
				 * 'is_dynamic' member is ignored here.
				 */
				xmlChar *fn;

				fn = xmlGetProp (n, (xmlChar *)"func");
				if (fn && *fn) {
					GSList *items, *i;
					struct _filter_option *op;

					option->dynamic_func = g_strdup ((const gchar *) fn);

					/* Get options now, to have them
					 * available when reading saved
					 * rules. */
					items = filter_option_get_dynamic_options (option);
					for (i = items; i; i = i->next) {
						op = i->data;

						if (op) {
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:evolution,代码行数:101,代码来源:e-filter-option.c

示例15: trParseParams

/**
 *  Parse command line for XSLT parameters
 */
int
trParseParams(const char** params, int* plen,
              int count, char **argv)
{
    int i;
    *plen = 0;
    params[0] = 0;

    for (i=0; i<count; i++)
    {
        if (argv[i][0] == '-')
        {
            if (!strcmp(argv[i], "-p"))
            {
                int j;
                xmlChar *name, *value;
                
                i++;
                if (i >= count) trUsage(argv[0], EXIT_BAD_ARGS);

                for(j=0; argv[i][j] && (argv[i][j] != '='); j++);
                if (argv[i][j] != '=') trUsage(argv[0], EXIT_BAD_ARGS);
                
                name = xmlStrndup((const xmlChar *) argv[i], j);
                value = xmlStrdup((const xmlChar *) argv[i]+j+1);

                if (*plen >= MAX_PARAMETERS)
                {
                    fprintf(stderr, "too many params increase MAX_PARAMETERS\n");
                    exit(EXIT_INTERNAL_ERROR);
                }

                params[*plen] = (char *)name;
                (*plen)++;
                params[*plen] = (char *)value;
                (*plen)++;                
                params[*plen] = 0;
            }
            else if (!strcmp(argv[i], "-s"))
            {
                int j;
                const xmlChar *string;
                xmlChar *name, *value;

                i++;
                if (i >= count) trUsage(argv[0], EXIT_BAD_ARGS);

                for(j=0; argv[i][j] && (argv[i][j] != '='); j++);
                if (argv[i][j] != '=') trUsage(argv[0], EXIT_BAD_ARGS);

                name = xmlStrndup((const xmlChar *)argv[i], j);
                string = (const xmlChar *)(argv[i]+j+1);

                if (xmlStrchr(string, '"'))
                {
                    if (xmlStrchr(string, '\''))
                    {
                        fprintf(stderr,
                            "string parameter contains both quote and double-quotes\n");
                        exit(EXIT_INTERNAL_ERROR);
                    }
                    value = xmlStrdup((const xmlChar *)"'");
                    value = xmlStrcat(value, string);
                    value = xmlStrcat(value, (const xmlChar *)"'");
                }
                else
                {
                    value = xmlStrdup((const xmlChar *)"\"");
                    value = xmlStrcat(value, string);
                    value = xmlStrcat(value, (const xmlChar *)"\"");
                }

                if (*plen >= MAX_PARAMETERS)
                {
                    fprintf(stderr, "too many params increase MAX_PARAMETERS\n");
                    exit(EXIT_INTERNAL_ERROR);
                }

                params[*plen] = (char *)name;
                (*plen)++;
                params[*plen] = (char *)value;
                (*plen)++;
                params[*plen] = 0;
            }
        }
        else
            break;
    }

    return i;    
}
开发者ID:bluecherrydvr,项目名称:omv,代码行数:94,代码来源:xml_trans.c


注:本文中的xmlStrdup函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。