Esempio n. 1
0
void clish_xmlnode_print(clish_xmlnode_t *node, FILE *out)
{
	node_t *roxn;
	char *name;

	roxn = xmlnode_to_node(node);
	name = roxml_get_name(roxn, NULL, 0);
	if (name) {
		fprintf(out, "<%s", name);
		roxml_release(name);
		if (roxml_get_attr_nb(roxn)) {
			int attr_count = roxml_get_attr_nb(roxn);
			int attr_pos;
			for (attr_pos = 0; attr_pos < attr_count; ++attr_pos) {
				node_t *attr = roxml_get_attr(roxn, NULL, attr_pos);
				char *n = roxml_get_name(attr, NULL, 0);
				char *v = roxml_get_content(attr, NULL, 0, NULL);
				if (n && v) {
					fprintf(out, " %s='%s'", n, v);
				}
				if (v) 
					roxml_release(v);
				if (n) 
					roxml_release(n);
			}
		}
		fprintf(out, ">");
	}
}
Esempio n. 2
0
node_t * ROXML_API roxml_get_chld(node_t *n, char * name, int nth)
{
	node_t *ptr = n;
	
	if(ptr == NULL) {
		return NULL;
	}
	
	ptr = n->chld;
	if(name == NULL)	{
		int count = 0;
		if(nth == 0)	{
			return ptr;
		}
		while((ptr->sibl)&&(nth > count)) {
			count++;
			ptr = ptr->sibl;
		}
		if(nth > count)	{ return NULL; }
	} else	{
		while(ptr) {
			int ans = strcmp(roxml_get_name(ptr, NULL, 0), name);
			roxml_release(RELEASE_LAST);
			if(ans == 0)	{
				return ptr;
			}
			ptr = ptr->sibl;
		}
	}
	return ptr;
}
Esempio n. 3
0
void clish_xmldoc_release(clish_xmldoc_t *doc)
{
	if (doc) {
		node_t *node = xmldoc_to_node(doc);
		roxml_release(RELEASE_ALL);
		roxml_close(node);
	}
}
Esempio n. 4
0
int main(int argc, char ** argv)
{
	int nb, len, ram;
	char input[128] = "test-1200K.xml";

	if(argc < 2)	{
		printf("no input file use '%s'\n", input);
	} else	{
		strncpy(input, argv[1], 128);
	}

	FILE * f = fopen(input, "r");
	if(f)	{
		fseek(f, 0, SEEK_END);
		len = ftell(f);
		fclose(f);
	} else	{
		printf("input file doesnt exist\n");
		return 1;
	}

	node_t *root = roxml_load_doc(input);

	int pgsize = 0;
	int size = 0;
	int resident = 0;
	int share = 0;
	int text = 0;
	int lib = 0;
	int data = 0;
	int dt = 0;
	char statfile[512];
	sprintf(statfile, "/proc/%d/statm", getpid());
	FILE * fstatfile = fopen(statfile, "r");
	if(fstatfile)   {
		fscanf(fstatfile, "%d %d %d %d %d %d %d", &size, &resident, &share, &text, &lib, &data, &dt);
		fclose(fstatfile);
	}
	pgsize = getpagesize();
	ram = pgsize*resident;

	node_t ** set = roxml_xpath(root, "//*", &nb);

	roxml_release(set);
	roxml_close(root);

	printf("stats for '%s':\n", input);
	printf("\tload_doc: %d bytes\n", len);
	printf("\txpath processed %d nodes\n", nb);
	printf("\ttotal node:\t\t\t %u\n",_nb_node);
	printf("\ttotal attr:\t\t\t %u\n",_nb_attr);
	printf("\ttotal text:\t\t\t %u\n",_nb_text);
	printf("\tram tree:\t\t\t %lu bytes\n",(long unsigned int)sizeof(node_t)*(_nb_node+_nb_attr+_nb_text));
	printf("\tram total:\t\t\t %d bytes\n",ram);
	printf("\tram ratio:\t\t\t %f\n",(float)(sizeof(node_t)*(_nb_node+_nb_attr+_nb_text))/(float)len);

	return 0;
}
Esempio n. 5
0
static int i_get_name(node_t *n, char *v, unsigned int *vl)
{
	char *c;
	int len;

	c = roxml_get_name(n, NULL, 0);
	if (c) {
		len = strlen(c) + 1;
		if (len <= *vl) {
			sprintf(v, "%s", c);
			roxml_release(c);
			return 0;
		} else {
			*vl = len;
			roxml_release(c);
			return -E2BIG;
		}
	}
	*vl = (unsigned int)-1;
	return -ENOMEM;
}
Esempio n. 6
0
static int i_get_content(node_t *n, char *v, unsigned int *vl)
{
	char *c;
	int len;

	c = roxml_get_content(n, NULL, 0, NULL);
	if (c) {
		len = strlen(c) + 1;
		if (len <= *vl) {
			i_decode_and_copy(v, c);
			roxml_release(c);
			return 0;
		} else {
			*vl = len;
			roxml_release(c);
			return -E2BIG;
		}
	}
	*vl = (unsigned int)-1;
	return -ENOMEM;
}
Esempio n. 7
0
int XHCPcmd_GETCONFIGXML (int sockd, int argc, char **argv)
{
    char *writeBuffer = NULL;
    
	XHCP_printXHCPResponse (sockd, RES_CFGDOCFOL ); // Configuration document follows
	
	roxml_commit_changes (rootConfig, NULL, &writeBuffer, 1);
	
	XHCP_print (sockd, writeBuffer);
	XHCP_print (sockd, ".");
	
	//free (writeBuffer);
	roxml_release(RELEASE_LAST);

    return XHCP_EXE_SUCCESS;
}
Esempio n. 8
0
int XHCP_loadConfig (node_t* argXmlConfig)
{
    node_t **result;
    int nb_result;
    char buffer[XHCP_BUFFER_SZ];
    int sz_buffer;
    char *xhcp_fileName;
    
    printf ("Loading XHCP server configuration...\n");
    
    if ( (xhcp_fileName = XHCP_getConfigFile ()) != NULL )
        domConfig = roxml_load_doc (xhcp_fileName);
    else if ( argXmlConfig != NULL )
        domConfig = argXmlConfig;
    else
        Error_Quit ("Unable to find XHCP configuration");
    
    
    /* Time Out */
    result = roxml_xpath ( domConfig, "//XHCPserver/ConnectionTimeOut[@delay]", &nb_result);
    if ( nb_result == 1 )
    {
        char *zaza = roxml_get_content ( roxml_get_attr (result[0], "delay", 0), buffer, XHCP_BUFFER_SZ, &sz_buffer );
        XHCP_connexionTimeOut = atoi (zaza);
        
        if ( XHCP_connexionTimeOut <= 0 )
            XHCP_connexionTimeOut=2;
    }
    else if ( nb_result == 0)
    {
        XHCP_connexionTimeOut = 5;
    }
    else
        Error_Quit ("Erroe parsing XHCP config file (ConnectionTimeOut)");
    
    roxml_release (RELEASE_LAST);
    printf ("XHCP_connexionTimeOut = %d\n", XHCP_connexionTimeOut);
    
    
    return 0;
}
Esempio n. 9
0
node_t ** ROXML_API roxml_xpath(node_t *n, char * path, int *nb_ans)
{
	int index = 0;
	int count = 0;
	xpath_node_t * xpath = NULL;
	node_t ** node_set = NULL;
	node_t * root = n;
	char * full_path_to_find;
	char * path_to_find;

	if(n == NULL)	{ 
		if(nb_ans) { *nb_ans = 0; }
		return NULL; 
	}

	root = roxml_get_root(n);

	full_path_to_find = strdup(path);
	path_to_find = full_path_to_find;

	index = roxml_parse_xpath(path_to_find, &xpath, 0);

	if(index >= 0) {
		node_set = roxml_exec_xpath(root, n, xpath, index, &count);

		roxml_free_xpath(xpath, index);
		free(full_path_to_find);

		if(count == 0)	{
			roxml_release(node_set);
			node_set = NULL;
		}
	}
	if(nb_ans)	{
		*nb_ans = count;
	}

	return node_set;
}
Esempio n. 10
0
int xcf_creator(int argc, char *project_path) {
	FILE* actor_src;
	int j, k, n,size_of_config, size_of_partitioning, size_of_partition, size_of_papi, len, actor_num, number_of_actions, number_of_events;
	int num = 0;
	node_t *configuration, *partitioning, *partition, *instance, *papi, *actor_instance, *action, *event;
	char *actor_path;

	char *mapping_file_path;

	if ((mapping_file_path = findMappingFile(project_path)) == NULL) {
		printf("Unable to locate a mapping file, make sure you are using the root path to the RVC CAL generated code with the C backend\n");
		exit(1);
	}

	int actors_num = get_actors_num(mapping_file_path);

	configuration = roxml_load_doc(mapping_file_path); //a: LIBROXML node http://www.libroxml.net/public-api.html
	if (configuration == NULL) {
		printf("I/O error when reading mapping file.\n");
		exit(1);
	}
	node_t *papi_root_node = roxml_add_node(configuration, 0, ROXML_ELM_NODE, "Papi", NULL);
	node_t *papi_instance_node, *papi_action_node, *papi_event_node;

	size_of_config = roxml_get_chld_nb(configuration); //a: This function return the number of children for a given node

	if(DEBUG)printf("Found %d configuration\n", size_of_config);


	partitioning = roxml_get_chld(configuration, NULL, 0); //a: This function returns a given child of a node either by name, or the nth child. (node, child name, number of the child to get)
	size_of_partitioning = roxml_get_chld_nb(partitioning); //a: This function return the number of children for a given node
	if(DEBUG)printf("	Found %d partitionings\n", size_of_partitioning);
	for (j = 0; j < size_of_partitioning; j++) {
		partition = roxml_get_chld(partitioning, NULL, j);
		if(DEBUG)printf("		Found partition, id = '%s'\n", roxml_get_content(roxml_get_attr(partition, "id", 0), NULL, 0, &len));
		size_of_partition = roxml_get_chld_nb(partition);
		for (k = 0; k < size_of_partition; k++) {
			instance = roxml_get_chld(partition, NULL, k);
			if(DEBUG)printf("			Found instance, id = '%s'\n", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));
			papi_instance_node = roxml_add_node(papi_root_node, 0, ROXML_ELM_NODE, "Instance", NULL);
			roxml_add_node(papi_instance_node, 0, ROXML_ATTR_NODE, "id", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));

			//this goes for every action in the actor:
			actor_path = malloc(strlen(project_path)+strlen(roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len))+10);
			strcpy(actor_path,project_path);
			actor_path = strcat(actor_path,"/src/");
			actor_path = strcat(actor_path,roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));
			actor_path = strcat(actor_path,".c");
			printf("opening %s\n", actor_path);
			actor_src = fopen(actor_path,"r");
			put_actions(actor_src, papi_instance_node, papi_action_node, papi_event_node);
			fclose(actor_src);
		}
	}

	char *mapping_file_cpy = malloc(strlen(mapping_file_path)+strlen(".papi.xcf")+1);

	strcpy(mapping_file_cpy, mapping_file_path);
	strcat(mapping_file_cpy, ".papi.xcf");



	//tmp = roxml_add_node(tmp, 0, ROXML_ELM_NODE, "price", "24");
	roxml_commit_changes(configuration, mapping_file_cpy, NULL, 1);
	//roxml_close(configuration);


	// release the last allocated buffer even if no pointer is maintained by the user
	roxml_release(RELEASE_LAST);
	// here no memory leak can occur.
	roxml_close(configuration);


	return 0;
}
Esempio n. 11
0
gboolean ots_load_xml_dictionary_buf(OtsArticle* Doc, const char* buffer) {
  char* head_name    = NULL;
  node_t* stem       = NULL;
  node_t* pre        = NULL;
  node_t* post       = NULL;
  node_t* syno       = NULL;        /* synonyms */
  node_t* manual     = NULL;        /* manual   */
  node_t* step1_pre  = NULL;        /* step1    */
  node_t* step1_post = NULL;        /* step1    */
  
  node_t* parse   = NULL;           /* parser rules */
  node_t* pbreak  = NULL;
  node_t* pdbreak = NULL;
  
  node_t* tc_words = NULL;          /* term count dictionary   */
  node_t* tf_words = NULL;          /* term frequency dictionary   */
  
  OtsStemRule* rule = Doc->stem;
  node_t* head = roxml_load_buf((char*)buffer);
  
  if (head == NULL) {
    fprintf(stderr, "empty document\n");
    roxml_release(RELEASE_ALL);
    return (FALSE);
  }
#if DEBUG > 1
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_name(head, NULL, 0));
#endif /* DEBUG > 1 */
  if (g_strcmp0(roxml_get_name(head, head_name, 0), (const char*)"dictionary")) {
    fprintf(stderr, "%s\n", head_name);
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  
  stem = roxml_get_chld(head, NULL, 0);
  if(stem == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&stem, (const char*)"stemmer");
  
  parse = roxml_get_chld(head, NULL, 0);
  if(parse == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&parse, (const char*)"parser");
  
  tc_words = roxml_get_chld(head, NULL, 0);
  if(tc_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&tc_words, (const char*)"grader-tc");
  
  tf_words = roxml_get_chld(head, NULL,  0);
  if(tf_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&tf_words, (const char*)"grader-tf");
  
  pre = roxml_get_chld(stem, NULL,  0);
  if(pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&pre, (const char*)"pre");
  
  post = roxml_get_chld(stem, NULL,  0);
  if(post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&post, (const char*)"post");
  
  syno = roxml_get_chld(stem, NULL, 0);
  if(syno == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&syno, (const char*)"synonyms");
  
  manual = roxml_get_chld(stem, NULL, 0);
  if(manual == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&manual, (const char*)"manual");
  
  step1_pre = roxml_get_chld(stem, NULL, 0);
  if(step1_pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&step1_pre, (const char*)"step1_pre");
  
  step1_post = roxml_get_chld(stem, NULL, 0);
  if(step1_post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&step1_post, (const char*)"step1_post");
  
  pre = roxml_get_chld(pre, NULL, 0); /* point to first word */
  if(pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->RemovePre, &pre);
  
  post = roxml_get_chld(post, NULL, 0);
  if(post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->RemovePost, &post);
  
  syno = roxml_get_chld(syno, NULL, 0);
  if(syno == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->synonyms, &syno);
  
  manual = roxml_get_chld(manual, NULL, 0);
  if(manual == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->manual, &manual);
  
  step1_pre = roxml_get_chld(step1_pre, NULL, 0);
  if(step1_pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->step1_pre, &step1_pre);
  
  step1_post = roxml_get_chld(step1_post, NULL, 0);
  if(step1_post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->step1_post, &step1_post);
  
  pbreak = roxml_get_chld(parse, NULL, 0);
  if(pbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&pbreak, (const char*)"linebreak");
  
  pdbreak = roxml_get_chld(parse, NULL, 0);
  if(pdbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&pdbreak, (const char*)"linedontbreak");
  
  /*Parser break*/
  pbreak = roxml_get_chld(pbreak, NULL, 0);
  if(pbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->ParserBreak, &pbreak);
  
  /*Parser Don't break*/
  pdbreak = roxml_get_chld(pdbreak, NULL, 0);
  if(pdbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->ParserDontBreak, &pdbreak);
  
  /* Term Count load dict */
  tc_words = roxml_get_chld(tc_words, NULL, 0);
  if(tc_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
#if DEBUG > 1
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_name(tc_words, NULL, 0));
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_content(tc_words, NULL, 0, NULL));
#endif /* DEBUG > 1 */
  while (tc_words != NULL) {
    if (!g_strcmp0(roxml_get_name(tc_words, NULL, 0), (const char*)"word")) {
      Doc->dict = g_list_prepend(Doc->dict,
        (gpointer)ots_new_wordEntery(
          (unsigned const char*)roxml_get_content(tc_words, NULL, 0, NULL)));
    }
    tc_words = roxml_get_next_sibling(tc_words);
#if DEBUG > 2
    fprintf(stdout, "%s\n", roxml_get_content(tc_words, NULL, 0, NULL));
#endif /* DEBUG > 2 */
  }
  
  /*Term Frequency load dict*/
  tf_words = roxml_get_chld(tf_words, NULL, 0);
  if(tf_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
#if DEBUG > 1
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_name(tf_words, NULL, 0));
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_content(tf_words, NULL, 0, NULL));
#endif /* DEBUG > 1 */
  while (tf_words != NULL) {
    if (!g_strcmp0(roxml_get_name(tf_words, NULL, 0), (const char*)"word")) {
      const gchar* key = g_strdup(roxml_get_content(tf_words, NULL, 0, NULL));
      node_t* idf_attr = roxml_get_attr(tf_words, "idf", 0);
      if (idf_attr != NULL) {
        const char* idf_val = roxml_get_content(idf_attr, NULL, 0, NULL);
        if (idf_val != NULL) {
#if DEBUG > 3
          fprintf(stdout, "%s\n", idf_val);
#endif /* DEBUG > 3 */
          Doc->tf_terms = g_list_append(Doc->tf_terms,
          ots_new_OtsWordTF((const unsigned char*)key, atof(idf_val)));
        }
      }
      g_free((gpointer)key);
    }
    tf_words = roxml_get_next_sibling(tf_words);
#if DEBUG > 2
    fprintf(stdout, "%s\n", roxml_get_content(tf_words, NULL, 0, NULL));
#endif /* DEBUG > 2 */
  }
  roxml_release(RELEASE_ALL);
  roxml_close(head);
  return (TRUE);
}
Esempio n. 12
0
void clish_xml_release(void *p)
{
	if (p) {
		roxml_release(p);
	}
}
Esempio n. 13
0
node_t * ROXML_API roxml_get_nodes(node_t *n, int type, char * name, int nth)
{
	node_t *ptr = NULL;
	
	if(n == NULL) {
		return NULL;
	}
	
	if(name == NULL)	{
		int count = 0;
		if(n->ns && (type & ROXML_NS_NODE)) {
			ptr = n->ns;
			if(nth == 0)	{
				return ptr;
			}
		} else if(n->attr && (type & ROXML_ATTR_NODE)) {
			ptr = n->attr;
			if(nth == 0)	{
				return ptr;
			}
			while((ptr->sibl)&&(nth > count)) {
				ptr = ptr->sibl;
				count++;
			}
		} else {
			ptr = n->chld;
			while(ptr && !((ptr->type & ROXML_NODE_TYPES) & type)) {
				ptr = ptr->sibl;
			}
		}
		if(nth > count)	{
			ptr = n->chld;
			while(ptr && !((ptr->type & ROXML_NODE_TYPES) & type)) {
				ptr = ptr->sibl;
			}
			while(ptr && (ptr->sibl) && (nth > count)) {
				ptr = ptr->sibl;
				if((ptr->type & ROXML_NODE_TYPES) & type) {
					count++;
				}
			}
		}
		if(nth > count)	{ return NULL; }
	} else	{
		if(n->attr && (type & ROXML_ATTR_NODE)) {
			ptr = n->attr;
			while(ptr) {
				int ans = strcmp(roxml_get_name(ptr, NULL, 0), name);
				roxml_release(RELEASE_LAST);
				if(ans == 0)	{
					return ptr;
				}
				ptr = ptr->sibl;
			}
		}
		ptr = n->chld;
		while(ptr) {
			if((ptr->type & ROXML_NODE_TYPES) & type) {
				int ans = strcmp(roxml_get_name(ptr, NULL, 0), name);
				roxml_release(RELEASE_LAST);
				if(ans == 0)	{
					return ptr;
				}
			}
			ptr = ptr->sibl;
		}
	}
	return ptr;
}
Esempio n. 14
0
int main(int ac, char *av[])
{
	node_t 			*doc;
	char			*xmlname = NULL;
	char			*xpquery = NULL;
	node_t 			**xpr = NULL;
	int 			opt = 0;
	int 			longopt = 0;
	int			flags = 0;

	/* getopt_long() should not display any message */
	opterr = 0; 

	while ((opt = getopt_long(ac, av, short_options, long_options, &longopt)) != -1) {
		switch (opt) {
		case 0:
			/*
			long option encountered
			we should not see any of them, because they are supposed to
			map to the corresponding short option. So if we get this, it
			might indicate that something is borked.
			*/
			break;
		case 1:
			/* not an option */
			if (!xmlname) {
				xmlname = strdup(av[optind-1]);
			} else if (!xpquery) {
				xpquery = strdup(av[optind-1]);
			} else {
				fprintf(stderr, "too many non-option - remove '%s'\n", av[optind - 1]);
				return EXIT_FAILURE;
			}
			break;
		case 'h':
			display_usage(av[0]);
			return EXIT_FAILURE;
		case 'q':
			flags |= ROCAT_FLAG_QUIET;
			break;
		case '?':
			fprintf(stderr, "unknown option '%s'\n", av[optind - 1]);
			return EXIT_FAILURE;
		default:
			break;
		}
	}

	if (!xmlname) {
		if ((flags & ROCAT_FLAG_QUIET) == 0) {
			fprintf(stderr, "invalid options: no XML file name\n\n");
			display_usage(av[0]);
		}
		return EXIT_FAILURE;
	}

	doc = roxml_load_doc(xmlname);
	if (!doc) {
		if ((flags & ROCAT_FLAG_QUIET) == 0)
			fprintf(stderr, "failed to load XML file '%s'\n", xmlname);
		goto on_error;
	}

	if (xpquery) {
		int xncount;

		xpr = roxml_xpath(doc, xpquery, &xncount);
		if (!xpr) {
			if ((flags & ROCAT_FLAG_QUIET) == 0)
				fprintf(stderr, "XPath query '%s' failed on '%s'\n", 
					xpquery, xmlname);
			goto on_error;
		}

		if (xncount) {
			int npos; 
			
			for (npos = 0; npos < xncount; ++npos) {
				char *buffer = NULL;
				node_t *xn = xpr[npos];;
				/* commit the node to stdout */
				roxml_commit_changes(xn, NULL, &buffer, 1);
				printf("%s\n", buffer);
				free(buffer);
			}
		} else {
			if ((flags & ROCAT_FLAG_QUIET) == 0)
				fprintf(stderr, "XPath query '%s' does not yield to any result\n", 
					xpquery);
			goto on_error;
		}

		roxml_release(xpr);

		free(xpquery);
	} else {
		char *buffer = NULL;
		/* commit everything to stdout */
		roxml_commit_changes(doc, NULL, &buffer, 1);
		printf("%s\n", buffer);
		free(buffer);
	}

	roxml_close(doc);

	free(xmlname);

	return EXIT_SUCCESS;

on_error:
	if (xpr) {
		roxml_release(xpr);
	}
	if (doc) roxml_close(doc);
	if (xmlname) free(xmlname);
	if (xpquery) free(xpquery);

	return EXIT_FAILURE;
}