Пример #1
0
void
save_feeds ()
{
  xmlDocPtr       doc;
  xmlNodePtr      root;
  GList          *ptr;
  gchar          *filename;
  xmlSaveCtxtPtr  ctxt;

  filename = g_build_filename (g_get_user_config_dir (),
                               PACKAGE,
                               "feeds.xml",
                               NULL);
  g_assert (filename != NULL);

  g_debug ("Writing %s", filename);
  
  doc = xmlNewDoc ((const xmlChar*) "1.0");
  g_assert (doc != NULL);

  root = xmlNewNode (NULL, (const xmlChar *) "feeds");
  g_assert (root != NULL);

  xmlDocSetRootElement (doc, root);

  for (ptr = g_list_first (feeds);
       ptr!= NULL;
       ptr = g_list_next (ptr)) {
    xmlNodePtr node;

    node = xmlNewNode (NULL, (const xmlChar *) "feed");
    g_assert (node != NULL);

    xmlNewChild (node, NULL, (const xmlChar *) "title",
                 (const xmlChar *) ((Feed *)ptr->data)->title);

    xmlNewChild (node, NULL, (const xmlChar *) "source",
                 (const xmlChar *) ((Feed *)ptr->data)->source);

    xmlAddChild (root, node);
  }

  ctxt = xmlSaveToFilename (filename, NULL, XML_SAVE_FORMAT);
  g_assert (ctxt != NULL);

  xmlSaveDoc (ctxt, doc);
  xmlSaveClose (ctxt);

  g_free (filename);
  xmlFreeDoc (doc);
}
Пример #2
0
bool XMLDocument::saveToHTMLFile(const std::string & filename, const bool indent) const
{
    int ret;
    int options = XML_SAVE_AS_HTML;
    if (indent)
    {
        options |= XML_SAVE_FORMAT;
    }

    xmlThrDefIndentTreeOutput(1);
    xmlSaveCtxtPtr ctxt = xmlSaveToFilename(filename.c_str(), 0, options);
    ret = xmlSaveDoc(ctxt, document);
    xmlSaveFlush(ctxt);
    xmlSaveClose(ctxt);

    return ret != -1;
}
Пример #3
0
/**
 *  Output document
 */
static void
edOutput(const char* filename, const XmlEdAction* ops, int ops_count,
    const edOptions* g_ops)
{
    xmlDocPtr doc;
    int save_options =
#if LIBXML_VERSION >= 20708
        (g_ops->noblanks? 0 : XML_SAVE_WSNONSIG) |
#endif
        (g_ops->preserveFormat? 0 : XML_SAVE_FORMAT) |
        (g_ops->omit_decl? XML_SAVE_NO_DECL : 0);
    int read_options =
        (g_ops->nonet? XML_PARSE_NONET : 0);
    xmlSaveCtxtPtr save;

    doc = xmlReadFile(filename, NULL, read_options);
    if (!doc)
    {
        cleanupNSArr(ns_arr);
        xmlCleanupParser();
        xmlCleanupGlobals();
        exit(EXIT_BAD_FILE);
    }

    edProcess(doc, ops, ops_count);

    /* avoid getting ASCII CRs in UTF-16/UCS-(2,4) text */
    if ((xmlStrcasestr(doc->encoding, BAD_CAST "UTF") == 0
            && xmlStrcasestr(doc->encoding, BAD_CAST "16") == 0)
        ||
        (xmlStrcasestr(doc->encoding, BAD_CAST "UCS") == 0
            && (xmlStrcasestr(doc->encoding, BAD_CAST "2") == 0
                ||
                xmlStrcasestr(doc->encoding, BAD_CAST "4") == 0)))
    {
        set_stdout_binary();
    }

    save = xmlSaveToFilename(g_ops->inplace? filename : "-", NULL, save_options);
    xmlSaveDoc(save, doc);
    xmlSaveClose(save);

    xmlFreeDoc(doc);
}
Пример #4
0
int lpc2xml_convert_file(lpc2xml_context* context, const char *filename) {
	int ret = -1;
	xmlSaveCtxtPtr save_ctx;
	lpc2xml_context_clear_logs(context);
	xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
	save_ctx = xmlSaveToFilename(filename, "UTF-8", XML_SAVE_FORMAT);
	if(save_ctx != NULL) {
		ret = internal_convert_lpc2xml(context);
		if(ret == 0) {
			ret = xmlSaveDoc(save_ctx, context->doc);
			if(ret != 0) {
				lpc2xml_log(context, LPC2XML_ERROR, "Can't save document");
				lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
			}
		}
		xmlSaveClose(save_ctx);
	} else {
		lpc2xml_log(context, LPC2XML_ERROR, "Can't open file:%s", filename);
		lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
	}
	return ret;
}
Пример #5
0
static void
saveState (CompDisplay *d,
	   const char  *clientId)
{
    char           *filename;
    struct passwd  *p = getpwuid (geteuid ());
    xmlDocPtr      doc = NULL;
    xmlSaveCtxtPtr ctx = NULL;
    CompScreen     *s;

    /* setup filename and create directories as needed */
    filename = malloc (sizeof (char) *
		       (strlen (p->pw_dir) + strlen (clientId) + 18));
    if (!filename)
	return;

    strcpy (filename, p->pw_dir);
    strcat (filename, "/.compiz");
    if (mkdir (filename, 0700) == 0 || errno == EEXIST)
    {
	strcat (filename, "/session");
	if (mkdir (filename, 0700) == 0 || errno == EEXIST)
	{
	    strcat (filename, "/");
	    strcat (filename, clientId);
	    ctx = xmlSaveToFilename (filename, NULL, XML_SAVE_FORMAT);
	}
    }

    free (filename);
    if (!ctx)
	return;

    doc = xmlNewDoc (BAD_CAST "1.0");
    if (doc)
    {
	xmlNodePtr rootNode;
	rootNode = xmlNewNode (NULL, BAD_CAST "compiz_session");
	if (rootNode)
	{
	    xmlNewProp (rootNode, BAD_CAST "id", BAD_CAST clientId);
	    xmlDocSetRootElement (doc, rootNode);

	    /* write out all windows on this display */
	    for (s = d->screens; s; s = s->next)
	    {
		CompWindow *w;

		for (w = s->windows; w; w = w->next)
		{
		    if (!isSessionWindow (w))
			continue;

		    if (!w->managed)
			continue;

		    sessionAddWindowNode (w, rootNode);
		}
	    }

	    xmlSaveDoc (ctx, doc);
	}

	xmlFreeDoc (doc);
    }

    xmlSaveClose (ctx);
}