Ejemplo n.º 1
0
int lpc2xml_convert_string(lpc2xml_context* context, char **content) {
	int ret = -1;
	xmlBufferPtr buffer = xmlBufferCreate();
	xmlSaveCtxtPtr save_ctx;
	lpc2xml_context_clear_logs(context);
	xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
	save_ctx = xmlSaveToBuffer(buffer, "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 initialize internal buffer");
		lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
	}
	if(ret == 0) {
#if LIBXML_VERSION >= 20800
		*content = (char *)xmlBufferDetach(buffer);
#else
		*content = strdup((const char *)xmlBufferContent(buffer));
#endif
	}
	xmlBufferFree(buffer);
	return ret;
}
Ejemplo n.º 2
0
int main(int argc, char * argv[])
{
	xmlNodePtr sentence;
	gchar ** tokens;

	GString * linebuffer = g_string_new("");

	GIOChannel * in = g_io_channel_unix_new(fileno(stdin));

	//首先读取一行文字
	g_io_channel_read_line_string(in,linebuffer,NULL,NULL);

	//分割
	tokens = g_strsplit_set(linebuffer->str," ",1024);

	//为此行文字打标记
	init_yylex(tokens);

	//打好词性标记后开始解析语法结构
	xmlInitGlobals();
	xmlInitMemory();
	yyparse(&sentence);
	xmlCleanupGlobals();
	xmlCleanupMemory();

	xmlSaveCtxtPtr saver = 	xmlSaveToFd(2,"UTF-8",0);

	xmlSaveTree(saver,sentence);
	xmlSaveFlush(saver);
	xmlSaveClose(saver);
	write(2,"\n",1);

	//输出语法树, 以 XML 形式
	return 0;
}
Ejemplo n.º 3
0
void XmlFileWriter::writeInternal(const char *pcszFilename, bool fSafe)
{
    WriteContext context(pcszFilename, fSafe);

    GlobalLock lock;

    /* serialize to the stream */
    xmlIndentTreeOutput = 1;
    xmlTreeIndentString = "  ";
    xmlSaveNoEmptyTags = 0;

    xmlSaveCtxtPtr saveCtxt;
    if (!(saveCtxt = xmlSaveToIO(WriteCallback,
                                 CloseCallback,
                                 &context,
                                 NULL,
                                 XML_SAVE_FORMAT)))
        throw xml::LogicError(RT_SRC_POS);

    long rc = xmlSaveDoc(saveCtxt, m->pDoc->m->plibDocument);
    if (rc == -1)
    {
        /* look if there was a forwarded exception from the lower level */
//         if (m->trappedErr.get() != NULL)
//             m->trappedErr->rethrow();

        /* there must be an exception from the Output implementation,
         * otherwise the save operation must always succeed. */
        throw xml::LogicError(RT_SRC_POS);
    }

    xmlSaveClose(saveCtxt);
}
Ejemplo n.º 4
0
/***********************************************
 *  生成XML的字符串                            *
 *  成功返回XML的字符串                        *
 *  失败则返回NULL                             *
 *  doc用完已自动清空                          *
 ***********************************************/
byte * generateXmlBuffer(xmlDocPtr doc)
{
	static byte szBuf[2048];
	byte * buffer;
	xmlBufferPtr buf = NULL;
    	xmlSaveCtxtPtr ctxt = NULL;
	LIBXML_TEST_VERSION;
	if(doc == NULL) {
		ErrorLog(ERROR, "doc is null");
		printf("doc is null");
		return NULL;
	}

	buf = xmlBufferCreate();
    	ctxt = xmlSaveToBuffer(buf, "UTF-8", 1);

    	xmlSaveDoc(ctxt, doc);
    	xmlSaveClose(ctxt);
	
	memset(szBuf, 0x00, sizeof(szBuf));
	buffer = u2g(buf->content);
	sprintf(szBuf, "%s",buffer );
	
	buf->content = NULL;
    	xmlBufferFree(buf);

    	xmlFreeDoc(doc);
    	xmlCleanupParser();
	
	free(buffer);
	return szBuf;
}
Ejemplo n.º 5
0
/**
 * Serialises an xmlNode to a string
 *
 * @param log   Log context
 * @param node Input XML node to be serialised
 *
 * @return Returns a pointer to a new buffer containing the serialised data.  This buffer must be freed
 *         after usage
 */
char *xmlNodeToString(LogContext *log, xmlNode *node) {
	xmlBuffer *buf = NULL;
	xmlSaveCtxt *serctx = NULL;
	char *ret = NULL;

	if( node == NULL ) {
		writelog(log, LOG_ALERT, "xmlNodeToString: Input data is NULL");
		return NULL;
	}

	buf = xmlBufferCreate();
	assert( buf != NULL );

	serctx = xmlSaveToBuffer(buf, "UTF-8", XML_SAVE_NO_EMPTY|XML_SAVE_NO_DECL);
	assert( serctx != NULL );

	if( xmlSaveTree(serctx, node) < 0 ) {
		writelog(log, LOG_ALERT, "xmlNodeToString: Failed to serialise xmlNode");
		return NULL;
	}
	xmlSaveClose(serctx);

	ret = strdup_nullsafe((char *) xmlBufferContent(buf));
	xmlBufferFree(buf);
	return ret;
}
Ejemplo n.º 6
0
static void info_doc_save_to_fd(xmlDocPtr doc, int fd)
{
	xmlSaveCtxtPtr xmlCtxt = xmlSaveToFd(fd, "UTF-8", XML_SAVE_FORMAT);

	if (xmlCtxt != NULL) {
		xmlSaveDoc(xmlCtxt, doc);
		xmlSaveClose(xmlCtxt);
	}
}
Ejemplo n.º 7
0
const std::string queryResult::to_xml()
{
	xmlDocPtr doc;
	xmlNodePtr root;
	int rc;
	std::string returnValue;

	doc = xmlNewDoc(BAD_CAST "1.0");
	root = xmlNewNode(NULL, BAD_CAST "result");

	std::stringstream temp;
	temp << size();
	xmlNewProp(root, BAD_CAST "count", BAD_CAST temp.str().c_str());

	if(__code != 0) {
		temp.str("");
		temp << __code;
		xmlNewProp(root, BAD_CAST "ocicode", BAD_CAST temp.str().c_str());
	}

	if(__info.length()) {
		xmlNewProp(root, BAD_CAST "ociinfo", BAD_CAST __info.c_str());
	}

	xmlDocSetRootElement(doc, root);


	for(int i=0; i<size(); ++i) {
			xmlNodePtr branch = xmlNewChild(root, NULL, BAD_CAST "branch", NULL);
	
			std::multimap<std::string, std::string>::iterator it, iend = at(i).end();
			for(it=at(i).begin(); it!=iend; ++it) {
						xmlNodePtr child = xmlNewChild(branch, NULL, BAD_CAST it->first.c_str(), BAD_CAST it->second.c_str());
					}
		}

	xmlNodePtr bind = xmlNewChild(root, NULL, BAD_CAST "bind", NULL);
	std::map<std::string, std::pair<std::string, bool> >::iterator j, jend = __bindouts.end();
	for(j = __bindouts.begin(); j != jend; ++j) {
		if(j->second.second == true)
			continue;
		xmlNodePtr child = xmlNewChild(bind, NULL, BAD_CAST j->first.c_str(), BAD_CAST j->second.first.c_str());
	}

	xmlBufferPtr buf = xmlBufferCreate();
	xmlSaveCtxtPtr sav = xmlSaveToBuffer(buf, "UTF-8", XML_SAVE_FORMAT | XML_SAVE_NO_EMPTY);

	xmlSaveDoc(sav, doc);
	xmlSaveClose(sav);

	returnValue = (char*)buf->content;

	xmlBufferFree(buf);
	xmlFreeDoc(doc);

	return returnValue;
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
int xmlSaveNode(void *node, void *encoding, int options) {
	xmlSaveCtxtPtr savectx;
	const char *c_encoding = (char*)encoding;

	savectx = xmlSaveToIO(
	      (xmlOutputWriteCallback)xml_write_callback,
	      (xmlOutputCloseCallback)close_callback,
	      NULL,
	      encoding,
	      options
	  );
	xmlSaveTree(savectx, (xmlNode*)node);
	return xmlSaveClose(savectx);
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
bool CXmlTree::WriteXmlFileToString(cvs::string& string) const
{
	xmlBufferPtr buffer = xmlBufferCreate();
	if(!buffer)
		return false;
	xmlSaveCtxtPtr save = xmlSaveToBuffer(buffer, NULL, 0);
	if(!save)
	{
		xmlBufferFree(buffer);
		return false;
	}
	xmlSaveDoc(save, m_doc);
	xmlSaveFlush(save);
	xmlSaveClose(save);
	string = (const char*)xmlBufferContent(buffer);
	xmlBufferFree(buffer);
	return true;
}
Ejemplo n.º 12
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);
}
Ejemplo n.º 13
0
    std::ostream& operator<< (std::ostream &stream, const xml::node &n) {
        node2doc n2d(n.pimpl_->xmlnode_);
        xmlDocPtr doc = n2d.get_doc();

        int libxml2_options = convert_to_libxml2_save_options(save_op_default);

        const char *  enc = NULL;
        if (n.pimpl_->xmlnode_->doc)
            enc = (const char *)(n.pimpl_->xmlnode_->doc->encoding);

        xmlSaveCtxtPtr  ctxt = xmlSaveToIO(save_to_stream_cb, NULL, &stream,
                                           enc, libxml2_options);

        if (ctxt) {
            xmlSaveDoc(ctxt, doc);
            xmlSaveClose(ctxt);     // xmlSaveFlush() is called in xmlSaveClose()
        }
        return stream;
    }
Ejemplo n.º 14
0
const std::string XMLDocument::dumpHTML(bool indent) const
{
    xmlBuffer * buffer = xmlBufferCreate();
    int ret;
    int options = XML_SAVE_AS_HTML;
    if (indent)
    {
        options |= XML_SAVE_FORMAT;
    }

    xmlThrDefIndentTreeOutput(1);
    xmlSaveCtxtPtr ctxt = xmlSaveToBuffer(buffer, 0, options);
    ret = xmlSaveDoc(ctxt, document);
    xmlSaveFlush(ctxt);
    xmlSaveClose(ctxt);

    std::string str((const char *)xmlBufferDetach(buffer));
    xmlBufferFree(buffer);

    return str;
}
Ejemplo n.º 15
0
// -------------------------------------------------------------
const char* Webpage::getNodeAsString(string exp)
{
	xmlXPathObjectPtr obj = xpath(exp);
	xmlNodeSetPtr nodeset = obj->nodesetval;
	if(nodeset && nodeset->nodeNr>0)
	{
		xmlBufferPtr buf = xmlBufferCreate();
		xmlSaveCtxtPtr savectx = xmlSaveToBuffer(buf, 0, XML_SAVE_FORMAT);
		xmlNodePtr node = nodeset->nodeTab[0];
		if (savectx)
		{
			xmlSaveTree(savectx, node);
			xmlSaveClose(savectx);
		}
		return (const char*)xmlBufferContent(buf);
	}
	else
	{	
		cout << "no node found" << endl;
		return "";
	}
}
Ejemplo n.º 16
0
int lpc2xml_convert_fd(lpc2xml_context* context, int fd) {
	int ret = -1;
	xmlSaveCtxtPtr save_ctx;
	lpc2xml_context_clear_logs(context);
	xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
	save_ctx = xmlSaveToFd(fd, "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 fd:%d", fd);
		lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
	}
	return ret;
}
Ejemplo n.º 17
0
/* Run an XPath query on XML on stdin, print results to stdout. */
static void
do_xpath (const char *query)
{
  CLEANUP_XMLFREEDOC xmlDocPtr doc = NULL;
  CLEANUP_XMLXPATHFREECONTEXT xmlXPathContextPtr xpathCtx = NULL;
  CLEANUP_XMLXPATHFREEOBJECT xmlXPathObjectPtr xpathObj = NULL;
  xmlNodeSetPtr nodes;
  char *r;
  size_t i;
  xmlSaveCtxtPtr saveCtx;
  xmlNodePtr wrnode;

  doc = xmlReadFd (STDIN_FILENO, NULL, "utf8", XML_PARSE_NOBLANKS);
  if (doc == NULL) {
    fprintf (stderr, _("%s: unable to parse XML from stdin\n"),
             guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

  xpathCtx = xmlXPathNewContext (doc);
  if (xpathCtx == NULL) {
    fprintf (stderr, _("%s: unable to create new XPath context\n"),
             guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

  xpathObj = xmlXPathEvalExpression (BAD_CAST query, xpathCtx);
  if (xpathObj == NULL) {
    fprintf (stderr, _("%s: unable to evaluate XPath expression\n"),
             guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

  switch (xpathObj->type) {
  case XPATH_NODESET:
    nodes = xpathObj->nodesetval;
    if (nodes == NULL)
      break;

    saveCtx = xmlSaveToFd (STDOUT_FILENO, NULL, XML_SAVE_NO_DECL | XML_SAVE_FORMAT);
    if (saveCtx == NULL) {
      fprintf (stderr, _("%s: xmlSaveToFd failed\n"), guestfs_int_program_name);
      exit (EXIT_FAILURE);
    }

    for (i = 0; i < (size_t) nodes->nodeNr; ++i) {
      CLEANUP_XMLFREEDOC xmlDocPtr wrdoc = xmlNewDoc (BAD_CAST "1.0");
      if (wrdoc == NULL) {
        fprintf (stderr, _("%s: xmlNewDoc failed\n"), guestfs_int_program_name);
        exit (EXIT_FAILURE);
      }
      wrnode = xmlCopyNode (nodes->nodeTab[i], 1);
      if (wrnode == NULL) {
        fprintf (stderr, _("%s: xmlCopyNode failed\n"),
                 guestfs_int_program_name);
        exit (EXIT_FAILURE);
      }

      xmlDocSetRootElement (wrdoc, wrnode);

      if (xmlSaveDoc (saveCtx, wrdoc) == -1) {
        fprintf (stderr, _("%s: xmlSaveDoc failed\n"),
                 guestfs_int_program_name);
        exit (EXIT_FAILURE);
      }
    }

    xmlSaveClose (saveCtx);

    break;

  case XPATH_STRING:
    r = (char *) xpathObj->stringval;
    printf ("%s", r);
    i = strlen (r);
    if (i > 0 && r[i-1] != '\n')
      printf ("\n");
    break;

  case XPATH_UNDEFINED: /* grrrrr ... switch-enum is a useless warning */
  case XPATH_BOOLEAN:
  case XPATH_NUMBER:
  case XPATH_POINT:
  case XPATH_RANGE:
  case XPATH_LOCATIONSET:
  case XPATH_USERS:
  case XPATH_XSLT_TREE:
  default:
    r = (char *) xmlXPathCastToString (xpathObj);
    printf ("%s\n", r);
    free (r);
  }
}
Ejemplo n.º 18
0
int
main ( int argc, char *argv[] )
{
//定义文档和节点指针
    //xmlDocPtr doc = xmlNewDoc(BAD_CAST"1.0");
    xmlDocPtr doc = xmlNewDoc(NULL);
    doc->standalone=-2;
    xmlNodePtr root_node = xmlNewNode(NULL,BAD_CAST"root");
    //设置根节点
    xmlDocSetRootElement(doc,root_node);
// cur = xmlDocGetRootElement(doc); //获取文档根结点
    //在根节点中直接创建节点
    xmlNewTextChild(root_node, NULL, BAD_CAST "newNode1", BAD_CAST "newNode1 content");
    xmlNewTextChild(root_node, NULL, BAD_CAST "newNode2", BAD_CAST "newNode2 content");
    xmlNewTextChild(root_node, NULL, BAD_CAST "newNode3", BAD_CAST "newNode3 content");
    /*
    xmlChar *key;
    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); //获取文本结点的文本,需用其子结点
    xmlFree(key);
    */

    //创建一个绑定在根节点的子节点
    xmlNewChild(root_node, NULL, BAD_CAST "node1",BAD_CAST "content of node1");
    /*
    xmlNodeSetContent(curNode, (xmlChar *) "content changed");//设置结点的文本内容
    //得到一个节点的内容:
    //xmlChar *value = xmlNodeGetContent(node);
    //返回值value应该使用xmlFree(value)释放内存

    xmlUnlinkNode(curNode); //将当前结点从文档中断链(unlink),这样本文档就不会再包含这个子结点
    xmlFreeNode(curNode); //手动删除断链结点的内存, 若没有xmlDelNode或者xmlRemoveNode,使用此函数

    xmlChar *uri;
    uri = xmlGetProp(cur, "uri"); //获取属性值
    xmlFree(uri); //释放内存

    xmlSetProp(curNode,BAD_(xmlChar *)"attribute", (xmlChar *) "no"); //设置当前结点的attribute属性的属性值为no
    */
    //创建一个节点,设置其内容和属性,然后加入根结点
    xmlNodePtr node = xmlNewNode(NULL,BAD_CAST"node2");
    xmlNodePtr content = xmlNewText(BAD_CAST"NODE CONTENT");
    xmlAddChild(root_node,node);
    xmlAddChild(node,content);
    xmlNewProp(node,BAD_CAST"attribute",BAD_CAST "yes");
    //通过xmlNewProp()增加一个节点的属性
    node=xmlNewChild(root_node, NULL, BAD_CAST "node3", BAD_CAST"node has attributes");
    xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "no");
    //创建一个儿子和孙子节点
    node = xmlNewNode(NULL, BAD_CAST "son");
    xmlAddChild(root_node,node);
    xmlNodePtr grandson = xmlNewNode(NULL, BAD_CAST "grandson");
    xmlAddChild(node,grandson);
    xmlAddChild(grandson, xmlNewText(BAD_CAST "This is a grandson node"));
    //存储xml文档
    int nRel = xmlSaveFile("CreatedXml.xml",doc);
    if (nRel != -1)
    {
       printf("%s\n",d_ConvertCharset("GBK", "utf-8", "一个xml文档被创建\n"));
    }

    //保存文件
    /*
     * xmlSaveFormatFile (docname, doc, 1); 保存文件到磁盘,第一个参数是写入文件的名,第二个参数是一个xmlDoc结构指针,第三个参数设定为1,保证在输出上写入缩进。
     */
    xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);
//    doc = xmlRecoverMemory(tmpxml,strlen(tmpxml));
//    xmlDocDumpMemoryEnc(doc, &buf, &len, "utf-8"); 

//    test_html();

    //释放文档内节点动态申请的内存
    xmlFreeDoc(doc);
    /*free the document */
    xmlCleanupParser();
    xmlMemoryDump();//debug memory for regression tests

    /*
     * 加载配置文件
     */
    pthread_attr_t attr;
    if(pthread_attr_init(&attr))
    {
        printf("err\n");
        return -1;
    }
    if(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))
    {
        printf("err\n");
        return -1;
    }
    if( pthread_create( &xmlcfg_tid, &attr, (void *(*)(void *))thread_checkconf, 0 ))
        printf("create err\n");
    pthread_attr_destroy(&attr);

    pthread_mutex_lock(&mtx);
    while(!xmlid)
        pthread_cond_wait(&cond,&mtx);
    pthread_mutex_unlock(&mtx);
    /* 注意:xmlReadFile可以控制option */
    printf("aaaa\n");
    //doc = xmlParseFile("beps.xml");
    doc = xmlReadFile("beps.xml","UTF-8", 1); //解析文件

    printf("aaaaaaaa\n");
    //int fd=open("log", O_WRONLY|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP );
    //ctxt = xmlSaveToFd(1, "UTF-8", -2);
    xmlSaveCtxtPtr ctxt = xmlSaveToFd(1, NULL, 1|-2);
    root_node=xmlDocGetRootElement( doc );
    //xmlSaveTree(ctxt, root_node);
    doc->encoding=NULL;
    xmlSaveDoc(ctxt, doc);
    xmlSaveClose(ctxt);
    xmlSaveFormatFileEnc( "-", doc, "UTF-8", 1);
    printf("aaaaaaaa\n");
    //doc = xmlReadFile("beps.xsd","UTF8",XML_PARSE_RECOVER); //解析文件
    //检查解析文件是否成功,如果不成功,libxml将指一个注册的错误并停止。
    //一个常见错误是不适当的编码。XML标准文件除了用UTF-8或UTF-16外还可用其他编码保存。
    //如果文件是这样,libxml将自动地为你转换到UTF-8。更多关于XML编码信息包含在XML标准中.
    if (NULL == doc)
    {  
       fprintf(stderr,"Document not parsed successfully.%d\n", __LINE__);
       return -1; 
    } 
//    printf("xmlDoc name=%s\n",doc->name);
//    printf("type=%d\n", doc->type);
////    printf("oldNs.href=%s\n",doc->oldNs->href);
////    printf("oldNs.prefix=%s\n",doc->oldNs->prefix);
//    printf("URL=%s\n",doc->URL);
//    printf("children.type=%u\n",doc->children->type);
//    printf("children.name=%s\n",doc->children->name);
//    printf("children.content=%s\n",doc->children->content);
//    if (doc->children->next)
//    {
//        printf("children.next.type=%u\n",doc->children->next->type);
//        printf("children.next.name=%s\n",doc->children->next->name);
//    }
//    //printf("children.next.content=%s\n",doc->children->next->content);
//    //printf("children.last.type=%u\n",doc->children->last->type);
//    //printf("children.last.name=%s\n",doc->children->last->name);
//    //printf("children.last.content=%s\n",doc->children->last->content);
//    root_node=xmlDocGetRootElement( doc );
//
//    printf("root.type=%u\n",      root_node->type);
//    printf("root.name=%s\n",      root_node->name);
//    printf("root.content=%s\n",   root_node->content);
//    if( root_node->next )
//    {
//        printf("root.next.type=%u\n", root_node->next->type);
//        printf("root.next.name=%s\n", root_node->next->name);
//    }
//
//    if( root_node->properties )
//    {
//        printf("root.prop.type=%u\n",   root_node->properties->type);
//        printf("root.prop.name=%s\n",   root_node->properties->name);
//        if (root_node->properties->ns)
//        {
//        printf("root.prop.ns.type=%u\n",   root_node->properties->ns->type);
//        printf("root.prop.ns.href=%s\n",   root_node->properties->ns->href);
//        printf("root.prop.ns.prefix=%s\n", root_node->properties->ns->prefix);
//        printf("root.prop.ns.next.type=%u\n",   root_node->properties->ns->next->type);
//        printf("root.prop.ns.next.href=%s\n",   root_node->properties->ns->next->href);
//        printf("root.prop.ns.next.prefix=%s\n", root_node->properties->ns->next->prefix);
//        }
//    }
//
//    if (root_node->ns)
//    {
//    printf("root.ns.type=%u\n",   root_node->ns->type);
//    printf("root.ns.href=%s\n",   root_node->ns->href);
//    printf("root.ns.prefix=%s\n", root_node->ns->prefix);
//    if (root_node->ns->next)
//    {
//    printf("root.ns.next.type=%u\n",   root_node->ns->next->type);
//    printf("root.ns.next.href=%s\n",   root_node->ns->next->href);
//    printf("root.ns.next.prefix=%s\n", root_node->ns->next->prefix);
//    }
//    }

    /*
     --------------------------------------------------------------------------------------------------
     XPATH查询函数
     --------------------------------------------------------------------------------------------------
     l  xmlXPathContextPtr context; //XPATH上下文指针
     l  context = xmlXPathNewContext(doc); //获取context指针
     l  xmlXPathObjectPtr result;// XPATH对象指针,用来存储查询结果
     l  result = xmlXPathEvalExpression(xmlChar *xpath, context); //根据条件xpath以及context来进行查询,条件格式:xmlChar *szXpath =(xmlChar *) ("/root/node2[@attribute='yes']");
     l  xmlXPathFreeContext(context); //释放context内存
     l  if(xmlXPathNodeSetIsEmpty(result->nodesetval)) //判断查询后的结果是否为空
     l  xmlNodeSetPtr nodeset; //创建结点集指针
     l  nodeset = result->nodesetval; //这个结点集对象包含在集合中的元素数目(nodeNr)及一个结点数组(nodeTab)。
     l  for (i=0; i < nodeset->nodeNr; i++) //遍历结果结点集合
     l  keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1)
     l  xmlXPathFreeObject (result); //释放内存
     l  xmlCleanupParser();//清除由libxml2申请的内存
     --------------------------------------------------------------------------------------------------
     */

//    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
//    int status = xmlXPathRegisterNs(xpathCtx,(const xmlChar *)"xs",
//      (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance");
//    status = xmlXPathRegisterNs(xpathCtx,(const xmlChar *)"ns",
//      (const xmlChar *)"urn:cnaps:std:beps:2010:tech:xsd:beps.121.001.01");
    xmlXPathObjectPtr result;
    //result=getNodeSet(doc, BAD_CAST"//node2[@attribute='yes']");
    //result=getNodeSet(doc, BAD_CAST"/root/*");
    //result=getNodeSet(doc, BAD_CAST"//newNode1");
    //result=getNodeSet(doc, "/Document/name[@id='1']/xcz");
//    result=getNodeSet(doc, "//element[@name='MsgId']");
    //result=xmlXPathEvalExpression("//xs:element[@name='MsgId']", xpathCtx);
    //result=xmlXPathEvalExpression(BAD_CAST"//ns:xcz[position()=2]", xpathCtx);
    //result=xmlXPathEvalExpression(BAD_CAST"/ns:Document/ns:name[@id='1']/ns:xcz", xpathCtx);
    //xmlXPathFreeContext(xpathCtx); //释放context内存
//    if(xmlXPathNodeSetIsEmpty(result->nodesetval)) //判断查询后的结果是否为空
//    {
//        xmlXPathFreeObject(result);
//        printf("nodeset is empty\n");
//        return 1;
//    }

    /*
    doc = xmlParseFile( FileName);
    xpathCtx = xmlXPathNewContext( doc);
    status = xmlXPathRegisterNs( xpathCtx,( const xmlChar *)"abc",
                      ( const xmlChar *)"http://www.abc.org");
                      */
//    printf("type=%d boolval=%d floatval=%lf stringval=%s\n", result->type, result->boolval, 
//                result->floatval, result->stringval);
//      xmlNodePtr nodet;
//      int n;
//      printf("nodeNr=%d nodeMax=%d\n", result->nodesetval->nodeNr, result->nodesetval->nodeMax );
//      n=result->nodesetval->nodeNr;
      int i;
//      nodet=*result->nodesetval->nodeTab;
//    while( n-- )
//    {
//        printf("type=[%d]\n", nodet->type);
//        printf("name=[%s]\n", nodet->name);
//        //printf("content=[%s]\n", nodet->content);
//        //printf("ns.href=[%s]ns.prefix=[%s]\n", nodet->ns->href, nodet->ns->prefix );
//        printf("attr.name=[%s]\n", nodet->properties->name);
//        printf("attr.children.content=[%s]\n", nodet->properties->children->content);
//        //printf("attr._private=[%s]\n", nodet->properties->_private);
//        //printf("children.content=[%s]\n", nodet->children->content);
//        nodet=*(result->nodesetval->nodeTab+i++);
//    }

//    xmlNodePtr cur;
//    xmlChar *value;
//    for (i=0; i < result->nodesetval->nodeNr; i++)
//    {
//        cur = result->nodesetval->nodeTab[i];
//       // cur = cur->xmlChildrenNode; 
//        if(cur!=NULL)
//        {  
//            value = xmlGetProp(cur,(const xmlChar *)"name");
//            if (value&&value[0])
//            {
//                printf("value: %s\n\n", d_ConvertCharset("utf-8", "GBK", (char *)value));
//                xmlFree(value);
//            }
//            value = xmlNodeGetContent(cur);
//            if (value&&value[0])
//            {
//                printf("value: %s\n\n", d_ConvertCharset("utf-8", "GBK", (char *)value));
//                xmlFree(value);
//            }
//        }
//    }

    //doc = xmlNewDoc(BAD_CAST"1.0");
    //printf("%d\n", __LINE__);
    //xmlDocSetRootElement(doc, *result->nodesetval->nodeTab);
    //printf("%d\n", __LINE__);
//    xmlSaveFile("1CreatedXml.xml",doc);
//    xml_tranid *xp;
//    xml_element *ep;
//    xp=xmlid;
    /*
     * 还需要考虑resolveconfig如何触发 可以起单独线程 间隔性检查文件修改时间
     * 另外修改时加读写锁
     * 遍历xmlid结构的方法 注意加读锁
     */
//    for( i=0; i<xmlnum; i++ )
//    {
//        printf("tranid=[%s]\n", xmlid[i].tranid);
//        ep=xmlid[i].ele;
//        while( ep )
//        {
//            printf("name=[%s]\n", ep->name);
//            printf("path=[%s]\n", ep->path);
//            printf("type=[%s]\n", ep->type);
//            printf("prop=[%s]\n", ep->prop);
//            ep=ep->next;
//        }
//    }


      /*
    int fd;
    fd=open("log", O_WRONLY|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP );
    if (fd==-1)
    {
        printf("open log err\n");
    }
    if (dup2(fd, STDOUT_FILENO)!=STDOUT_FILENO)
    {
        printf("dup stdout err\n");
    }
    */


    char buf[128];
    if(!getxmlvalue( doc, "1111", "id1", 0, buf ))
        printf("get value err\n");
    printf("%s\n", buf);
    if(!getxmlvalue( doc, "1111", "nameid", 0, buf ))
        printf("get value err\n");
    printf("%s\n", buf);
    xmlFreeDoc(doc);
    /*free the document */
    xmlCleanupParser();
    xmlMemoryDump();//debug memory for regression tests
    while(1)
    {
    costt(1,0);
    doc = xmlParseFile("beps.xml");
        if(!getxmlvalue( doc, "1111", "count", 0, &i ))
            printf("get value err\n");
        printf("%d\n", i);
    xmlFreeDoc(doc);
    /*free the document */
    xmlCleanupParser();
    xmlMemoryDump();//debug memory for regression tests
    printf("%lf\n", costt(1,1));
        sleep(1);
    }
//    xmlXPathFreeObject (result);
    return EXIT_SUCCESS;
}               /* ----------  end of function main  ---------- */
Ejemplo n.º 19
0
static gboolean xspf_playlist_save (const gchar * filename, VFSFile * file,
 const gchar * title, Index * filenames, Index * tuples)
{
    gint entries = index_count (filenames);
    xmlDocPtr doc;
    xmlNodePtr rootnode, tracklist;
    gint count;

    doc = xmlNewDoc((xmlChar *)"1.0");
    doc->charset = XML_CHAR_ENCODING_UTF8;
    doc->encoding = xmlStrdup((xmlChar *)"UTF-8");

    rootnode = xmlNewNode(NULL, (xmlChar *)XSPF_ROOT_NODE_NAME);
    xmlSetProp(rootnode, (xmlChar *)"version", (xmlChar *)"1");
    xmlSetProp(rootnode, (xmlChar *)"xmlns", (xmlChar *)XSPF_XMLNS);

    /* common */
    xmlDocSetRootElement(doc, rootnode);

    if (title)
        xspf_add_node (rootnode, TUPLE_STRING, FALSE, "title", title, 0);

    tracklist = xmlNewNode(NULL, (xmlChar *)"trackList");
    xmlAddChild(rootnode, tracklist);

    for (count = 0; count < entries; count ++)
    {
        const gchar * filename = index_get (filenames, count);
        const Tuple * tuple = index_get (tuples, count);
        xmlNodePtr track, location;
        gchar *scratch = NULL;
        gint scratchi = 0;

        track = xmlNewNode(NULL, (xmlChar *)"track");
        location = xmlNewNode(NULL, (xmlChar *)"location");

        xmlAddChild(location, xmlNewText((xmlChar *)filename));
        xmlAddChild(track, location);
        xmlAddChild(tracklist, track);

        if (tuple != NULL)
        {
            gint i;
            for (i = 0; i < xspf_nentries; i++) {
                const xspf_entry_t *xs = &xspf_entries[i];
                gboolean isOK = (tuple_get_value_type (tuple, xs->tupleField,
                 NULL) == xs->type);

                switch (xs->type) {
                    case TUPLE_STRING:
                        scratch = tuple_get_str (tuple, xs->tupleField, NULL);
                        if (! scratch)
                            isOK = FALSE;
                        str_unref(scratch);
                        break;
                    case TUPLE_INT:
                        scratchi = tuple_get_int (tuple, xs->tupleField, NULL);
                        break;
                    default:
                        break;
                }

                if (isOK)
                    xspf_add_node(track, xs->type, xs->isMeta, xs->xspfName, scratch, scratchi);
            }
        }
    }

    xmlSaveCtxt * save = xmlSaveToIO (write_cb, close_cb, file, NULL,
     XML_SAVE_FORMAT);
    if (! save)
        goto ERR;

    if (xmlSaveDoc (save, doc) < 0 || xmlSaveClose (save) < 0)
        goto ERR;

    xmlFreeDoc(doc);
    return TRUE;

ERR:
    xmlFreeDoc (doc);
    return FALSE;
}
Ejemplo n.º 20
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);
}
static gchar*
rb_disc_recorder_plugin_write_audio_project (const gchar 	*name,
					     GtkTreeModel       *model,
					     GError		**error)
{
        GtkTreeIter iter;
	xmlTextWriter *project;
	xmlDocPtr doc = NULL;
	xmlSaveCtxt *save;
	gint success;
    	gchar *path;
	int fd;
	int use_errno = 0;

        if (! gtk_tree_model_get_iter_first (model, &iter)) {
                g_set_error (error,
                             RB_RECORDER_ERROR,
                             RB_RECORDER_ERROR_GENERAL,
                             _("Unable to build an audio track list"));
                return NULL;
        }

	/* get a temporary path */
	path = g_build_filename (g_get_tmp_dir (), "brasero-tmp-project-XXXXXX",  NULL);
	fd = g_mkstemp (path);
	if (fd == -1) {
		g_set_error (error,
                 	     RB_RECORDER_ERROR,
                     	     RB_RECORDER_ERROR_GENERAL,
                    	     _("Unable to write audio project file %s: %s"),
			     path,
			     g_strerror (errno));
		rb_debug ("g_mkstemp failed");

		g_free (path);
		return NULL;
	}

	project = xmlNewTextWriterDoc (&doc, 0);
	if (!project) {
		g_remove (path);
		g_free (path);
		close (fd);

		g_set_error (error,
                 	     RB_RECORDER_ERROR,
                     	     RB_RECORDER_ERROR_GENERAL,
                    	     _("Unable to write audio project"));

		return NULL;
	}

	xmlTextWriterSetIndent (project, 1);
	xmlTextWriterSetIndentString (project, (xmlChar *) "\t");

	success = xmlTextWriterStartDocument (project,
					      NULL,
					      "UTF8",
					      NULL);
	if (success < 0)
		goto error;

	success = xmlTextWriterStartElement (project, (xmlChar *) "braseroproject");
	if (success < 0)
		goto error;

	/* write the name of the version */
	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "version",
					     (xmlChar *) "0.2");
	if (success < 0)
		goto error;

	if (name) {
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "label",
						     (xmlChar *) name);
		if (success < 0)
			goto error;
	}

	success = xmlTextWriterStartElement (project, (xmlChar *) "track");
	if (success < 0)
		goto error;

        do {
		RhythmDBEntry  *entry;
		const char *str;
		xmlChar *escaped;

		success = xmlTextWriterStartElement (project, (xmlChar *) "audio");
		if (success < 0)
			goto error;

		gtk_tree_model_get (model, &iter, 0, &entry, -1);

		str = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
		escaped = (xmlChar *) g_uri_escape_string (str, NULL, FALSE);
		success = xmlTextWriterWriteElement (project,
						    (xmlChar *) "uri",
						     escaped);
		g_free (escaped);

		if (success == -1)
			goto error;

		/* start of the song always 0 */
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "start",
						     (xmlChar *) "0");
		if (success == -1)
			goto error;

		/* end of the song = duration (in seconds while brasero likes it
		 * in nanoseconds =( ) */
		/* Disable this for the moment and let brasero check the size
		 * itself. In case the user chooses on the fly burning we need
		 * a more precise duration or we'd end up burning the track
		 * incompletely or with a big padding */
		/*
		end = g_strdup_printf ("%"G_GINT64_FORMAT, (gint64) (song->duration * 1000000000LL));
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "end",
						     (xmlChar *) end);

		g_free (end);
		if (success == -1)
			goto error;
		*/

		str = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE);
		if (str) {
			escaped = (xmlChar *) g_uri_escape_string (str, NULL, FALSE);
			success = xmlTextWriterWriteElement (project,
							    (xmlChar *) "title",
							     escaped);
			g_free (escaped);

			if (success == -1)
				goto error;
		}

		str = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST);
		if (str) {
			escaped = (xmlChar *) g_uri_escape_string (str, NULL, FALSE);
			success = xmlTextWriterWriteElement (project,
							    (xmlChar *) "artist",
							     escaped);
			g_free (escaped);

			if (success == -1)
				goto error;
		}

		/*
		if (song->composer) {
			escaped = (unsigned char *) g_uri_escape_string (song->composer, NULL, FALSE);
			success = xmlTextWriterWriteElement (project,
							    (xmlChar *) "composer",
							     escaped);
			g_free (escaped);

			if (success == -1)
				goto error;
		}
		*/

		success = xmlTextWriterEndElement (project); /* audio */
		if (success < 0)
			goto error;
        } while (gtk_tree_model_iter_next (model, &iter));

	success = xmlTextWriterEndElement (project); /* track */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndElement (project); /* braseroproject */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndDocument (project);
	if (success < 0)
		goto end_error;

	xmlFreeTextWriter (project);

	save = xmlSaveToFd (fd, "UTF8", XML_SAVE_FORMAT);
	if (save == NULL)
		goto save_error;

	if (xmlSaveDoc (save, doc) == -1)
		goto save_error;

	if (xmlSaveClose (save) == -1) {
		use_errno = errno;
		rb_debug ("xmlSaveClose failed");
		goto save_error;
	}

	xmlFreeDoc (doc);

	if (close (fd) == -1) {
		use_errno = errno;
		rb_debug ("close() failed");
		goto save_error;
	}

	return path;

error:
	/* cleanup */
	xmlTextWriterEndDocument (project);

end_error:
	xmlFreeTextWriter (project);

save_error:
	if (use_errno != 0) {
		g_set_error (error,
			     RB_RECORDER_ERROR,
			     RB_RECORDER_ERROR_GENERAL,
			     _("Unable to write audio project file %s: %s"),
			     path,
			     g_strerror (use_errno));
	} else {
		g_set_error (error,
			     RB_RECORDER_ERROR,
			     RB_RECORDER_ERROR_GENERAL,
			     _("Unable to write audio project"));
	}

	g_remove (path);
	g_free (path);
	close (fd);

	return NULL;
}
Ejemplo n.º 22
0
static char*
totem_disc_recorder_plugin_write_video_project (TotemDiscRecorderPlugin *pi,
						char **error)
{
	xmlTextWriter *project;
	xmlDocPtr doc = NULL;
	xmlSaveCtxt *save;
	xmlChar *escaped;
	gint success;
	char *title, *path, *uri;
	int fd;

	/* get a temporary path */
	path = g_build_filename (g_get_tmp_dir (), "brasero-tmp-project-XXXXXX",  NULL);
	fd = g_mkstemp (path);
	if (!fd) {
		g_free (path);

		*error = g_strdup (_("Unable to write a project."));
		return NULL;
	}

	project = xmlNewTextWriterDoc (&doc, 0);
	if (!project) {
		g_remove (path);
		g_free (path);
		close (fd);

		*error = g_strdup (_("Unable to write a project."));
		return NULL;
	}

	xmlTextWriterSetIndent (project, 1);
	xmlTextWriterSetIndentString (project, (xmlChar *) "\t");

	success = xmlTextWriterStartDocument (project,
					      NULL,
					      "UTF8",
					      NULL);
	if (success < 0)
		goto error;

	success = xmlTextWriterStartElement (project, (xmlChar *) "braseroproject");
	if (success < 0)
		goto error;

	/* write the name of the version */
	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "version",
					     (xmlChar *) "0.2");
	if (success < 0)
		goto error;

	title = totem_object_get_short_title (pi->priv->totem);
	if (title) {
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "label",
						     (xmlChar *) title);
		g_free (title);

		if (success < 0)
			goto error;
	}

	success = xmlTextWriterStartElement (project, (xmlChar *) "track");
	if (success < 0)
		goto error;

	success = xmlTextWriterStartElement (project, (xmlChar *) "video");
	if (success < 0)
		goto error;

	uri = totem_object_get_current_mrl (pi->priv->totem);
	escaped = (unsigned char *) g_uri_escape_string (uri, NULL, FALSE);
	g_free (uri);

	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "uri",
					     escaped);
	g_free (escaped);
	if (success == -1)
		goto error;

	/* start of the song always 0 */
	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "start",
					     (xmlChar *) "0");
	if (success == -1)
		goto error;

	success = xmlTextWriterEndElement (project); /* video */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndElement (project); /* track */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndElement (project); /* braseroproject */
	if (success < 0)
		goto error;

	xmlTextWriterEndDocument (project);
	xmlFreeTextWriter (project);

	save = xmlSaveToFd (fd, "UTF8", XML_SAVE_FORMAT);
	xmlSaveDoc (save, doc);
	xmlSaveClose (save);

	xmlFreeDoc (doc);
	close (fd);

	return path;

error:

	/* cleanup */
	xmlTextWriterEndDocument (project);
	xmlFreeTextWriter (project);

	g_remove (path);
	g_free (path);
	close (fd);

	*error = g_strdup (_("Unable to write a project."));
	return NULL;
}