コード例 #1
0
ファイル: main.c プロジェクト: microcai/thesis
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;
}
コード例 #2
0
ファイル: armadito-info.c プロジェクト: 41434944/armadito-av
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);
	}
}
コード例 #3
0
ファイル: lpc2xml.c プロジェクト: Accontech/ace-ios
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;
}
コード例 #4
0
ファイル: inspector.c プロジェクト: myyyy/libguestfs
/* 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);
  }
}
コード例 #5
0
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;
}
コード例 #6
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;
}
コード例 #7
0
ファイル: xml.c プロジェクト: xiongshaogang/space
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  ---------- */