Example #1
0
int
RS_XML(libXMLEventParse)(const char *fileName, RS_XMLParserData *parserData, RS_XML_ContentSourceType asText,
                          int saxVersion)
{
 xmlSAXHandlerPtr xmlParserHandler;
 xmlParserCtxtPtr ctx; 
 int status;

  switch(asText) {
    case RS_XML_TEXT:
      ctx = xmlCreateDocParserCtxt(CHAR_TO_XMLCHAR(fileName));
      break;

    case RS_XML_FILENAME:
      ctx = xmlCreateFileParserCtxt(fileName);
      break;

    case RS_XML_CONNECTION:
      ctx = RS_XML_xmlCreateConnectionParserCtxt((USER_OBJECT_) fileName);

      break;
    default:
      ctx = NULL;
  }


  if(ctx == NULL) {
    PROBLEM "Can't parse %s", fileName
    ERROR;
  }


  xmlParserHandler = (xmlSAXHandlerPtr) S_alloc(sizeof(xmlSAXHandler), 1);
  /* Make certain this is initialized so that we don't have any references  to unwanted routines!  */
  memset(xmlParserHandler, '\0', sizeof(xmlSAXHandler));

  RS_XML(initXMLParserHandler)(xmlParserHandler, saxVersion);

  parserData->ctx = ctx;
  ctx->userData = parserData;
  ctx->sax = xmlParserHandler;

  status = xmlParseDocument(ctx);

  ctx->sax = NULL;
  xmlFreeParserCtxt(ctx);

  return(status);

/*  Free(xmlParserHandler); */
}
/* call-seq:
 *    XML::Parser::Context.document(document) -> XML::Parser::Context
 *
 * Creates a new parser context based on the specified document.
 *
 * Parameters:
 *
 *  document - An XML::Document instance.
 */
static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
{
  xmlParserCtxtPtr ctxt;
  xmlDocPtr xdoc;
  xmlChar *buffer; 
  int length;

  if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
    rb_raise(rb_eTypeError, "Must pass an XML::Document object");

  Data_Get_Struct(document, xmlDoc, xdoc);
  xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, xdoc->encoding, 0);

  ctxt = xmlCreateDocParserCtxt(buffer);
  return rxml_parser_context_wrap(ctxt);
}
Example #3
0
File: utils.c Project: rosedu/osmo
void
utl_xml_get_strn (gchar *name, gchar *sname, gint buffer_size, xmlNodePtr node)
{
	xmlParserCtxtPtr context;
	xmlChar *key, *out;

	if ((xmlStrcmp (node->name, (const xmlChar *) name)) == 0) {

		key = xmlNodeGetContent (node->xmlChildrenNode);
		context = xmlCreateDocParserCtxt (key);
		out = (xmlChar*) xmlStringDecodeEntities (context, key, XML_SUBSTITUTE_REF, 0, 0, 0);
		xmlFreeParserCtxt (context);
		xmlFree (key);

		if (out != NULL) {
			g_strlcpy (sname, (gchar *) out, buffer_size);
			xmlFree (out);
		}
	}
}
Example #4
0
static gboolean
xml_read_string (MrpFileReader  *reader,
		 const gchar    *str,
		 MrpProject     *project,
		 GError        **error)
{
	xmlParserCtxt *ctxt;
	gboolean       ret_val;

	g_return_val_if_fail (str != NULL, FALSE);

	ctxt = xmlCreateDocParserCtxt ((xmlChar* ) str);
	if (!ctxt) {
		return FALSE;
	}

	ret_val = xml_read_context (ctxt, project, error);

 	xmlFreeParserCtxt (ctxt);

	return ret_val;
}
Example #5
0
File: xml.c Project: MigNov/pvr
char *xml_query_by_id(char *xmlFile, char *xPath, int id) {
	xmlDocPtr doc;
	xmlParserCtxtPtr pctxt;
	xmlXPathContextPtr context;
	xmlXPathObjectPtr op;
	xmlNodeSetPtr nodeset;
	char *data = NULL;
	int num;

	if ((xmlFile == NULL) || (strlen(xmlFile) < 1))
		return NULL;

	if (xmlFile[0] != '<') {
		if (access(xmlFile, R_OK) != 0) {
			fprintf(stderr, "Error: File %s doesn't exist or is not accessible for reading.\n", xmlFile);
			return NULL;
		}

		doc = xmlParseFile(xmlFile);
	}
	else {
		pctxt = xmlCreateDocParserCtxt((xmlChar *)xmlFile);
		doc = xmlCtxtReadDoc(pctxt, (xmlChar *)xmlFile, NULL, NULL, XML_PARSE_NOWARNING | XML_PARSE_NOERROR);

		/* A little hack, but working */
		do { char tmp[1024] = { 0 }; char *dtmp = get_datetime(); snprintf(tmp, sizeof(tmp), "[%s ", dtmp); free(dtmp); dtmp=NULL; } while (0);
	}

	context = xmlXPathNewContext(doc);
	if (context == NULL) {
		DPRINTF("Error in xmlXPathNewContext\n");
		return NULL;
	}

	DPRINTF("Trying to access xPath node %s (pos %d)\n", xPath, id);
	op = xmlXPathEvalExpression( (xmlChar *)xPath, context);
	xmlXPathFreeContext(context);
	if (op == NULL) {
		DPRINTF("Error in xmlXPathEvalExpression\n");
		return NULL;
	}

	if(xmlXPathNodeSetIsEmpty(op->nodesetval)){
		xmlXPathFreeObject(op);
		DPRINTF("No result\n");
		return NULL;
	}

	nodeset = op->nodesetval;
	num = nodeset->nodeNr;

#if 0
	for (i = 0; i < num; i++) {
		data = (char *)xmlNodeListGetString(doc, (nodeset->nodeTab[i])->xmlChildrenNode, 1);
		DPRINTF("%d. >>> %s\n", i, data);
	}
#endif

	DPRINTF("Current num value is %d, id value is %d\n", num, id);
	if (num > id) {
		char *tmp = (char *)xmlNodeListGetString(doc, (nodeset->nodeTab[id])->xmlChildrenNode, 1);

		data = strdup(tmp);
		DPRINTF("Got data element of '%s'\n", tmp);
	}
	else
		DPRINTF("Trying to access element out of bounds (id > num)\n");

	xmlXPathFreeObject(op);

	xmlFreeDoc(doc);
	xmlCleanupParser();

	return data;
}
Example #6
0
char *xmlrpc_parse(char *xml)
{
	xmlParserCtxtPtr xp;
	xmlDocPtr doc;
	xmlXPathContextPtr context;
	xmlXPathObjectPtr result;
	xmlNodeSetPtr nodeset;
	char *methodName = NULL;
	char *ret = NULL;
	int i;

	_xmlrpc_vars = NULL;
	_xmlrpc_vars_num = 0;

	_xlastElementNames = NULL;
	_xlastElementNames_num = 0;

	_xIdParent = 0;

	/* We need to strip the new line characters as it's making issues */
	while (strstr(xml, "\n") != NULL)
		xml = replace(xml, "\n", "");

	DPRINTF("Parsing XML:\n%s\n", xml);

	xp = xmlCreateDocParserCtxt( (xmlChar *)xml );
	if (!xp) {
		DPRINTF("Cannot create DocParserCtxt\n");
		return NULL;
	}

	doc = xmlCtxtReadDoc(xp, (xmlChar *)xml, NULL, NULL, 0);
	if (!doc) {
		DPRINTF("Cannot get xmlDocPtr\n");
		return NULL;
	}

	context = xmlXPathNewContext(doc);
	if (!context) {
		DPRINTF("Cannot get new XPath context\n");
		return NULL;
	}

	result = xmlXPathEvalExpression( (xmlChar *)"//methodCall/methodName", context);
	if (!result) {
		xmlXPathFreeContext(context);
		DPRINTF("Cannot evaluate expression\n");
		goto cleanup;
	}
	if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
		xmlXPathFreeObject(result);
		xmlXPathFreeContext(context);
		DPRINTF("Nothing found\n");
		goto cleanup;
	}
	nodeset = result->nodesetval;
	if (nodeset->nodeNr != 1) {
		xmlXPathFreeObject(result);
		xmlXPathFreeContext(context);
		DPRINTF("Invalid number of methodName elements\n");
		goto cleanup;
	}

	methodName = (char *)xmlNodeListGetString(doc, nodeset->nodeTab[0]->xmlChildrenNode, 1);
	xmlXPathFreeObject(result);

	result = xmlXPathEvalExpression( (xmlChar *)"//methodCall/params/param", context);
	nodeset = result->nodesetval;

	for (i = 0; i < nodeset->nodeNr; i++) {
	        xmlrpc_process_param(doc, nodeset->nodeTab[i], 0, 1);
	}

	ret = strdup(methodName);
cleanup:
	xmlXPathFreeObject(result);
	xmlFreeDoc(doc);
	xmlCleanupParser();

	return ret;
}