Ejemplo n.º 1
0
 std::auto_ptr<document> dom_parser::parse_url(const std::string& url, const std::string& proxy)
 {
     set_global_variables global_variables;
     // Create a libxml2 parser context for parsing the xml string.
     if (url.empty())
     {
         throw dom_error("fail to parse remote xml: URL is null");
     }
     // Set the HTTP proxy URL.
     set_nano_http_proxy set_proxy(proxy);
     // Create a libxml2 parser context for parsing the URL.
     dom_parser_context_wrapper context( xmlCreateURLParserCtxt(url.c_str(), 0) );
     if (context.get() == 0)
     {
         throw dom_error("Fail to parse remote xml: unable to create libxml2 parser context");
     }
     // Parse remote xml under the constructed parser context.
     xmlDoc* px = parse_in_context(context.get());
     assert(px != 0);
     return std::auto_ptr<document>(new document(px));
 }
Ejemplo n.º 2
0
/* call-seq:
 *    XML::Parser::Context.file(file) -> XML::Parser::Context
 *
 * Creates a new parser context based on the specified file or uri.
 *
 * Parameters:
 *
 *  file - A filename or uri.
*/
static VALUE rxml_parser_context_file(VALUE klass, VALUE file)
{
  xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0);
  return rxml_parser_context_wrap(ctxt);
}
Ejemplo n.º 3
0
void
xml_tree_model_add_file (	xmlTreeModel	*model,
							gchar			*filename)
{
	g_return_if_fail (XML_IS_TREE_MODEL(model));
	g_return_if_fail (filename != NULL);

	GtkTreeIter   		iter;
	xsltStylesheetPtr 	xsldoc;
	xmlDocPtr			xmldoc = NULL;
	xmlNodePtr			cur;

    model->parser = xmlCreateURLParserCtxt (filename,
											XML_PARSE_RECOVER);// | 
											//XML_PARSE_DTDVALID);

	g_return_if_fail(model->parser != NULL);
            
    int record_info	= 1;
	xmlSetFeature(model->parser, "gather line info", &record_info);	

	xmlParseDocument(model->parser);

	glong bytes = xmlByteConsumed(model->parser);
		
 	model->valid = (model->parser->valid == 0) ? FALSE : TRUE;

	xmldoc = model->parser->myDoc;

	g_return_if_fail (xmldoc != NULL);

	model->offset = get_offset(xmldoc, filename);

	gint i;
	xmlParserNodeInfoPtr node;

	for(i = 0; i < model->parser->node_seq.length; ++i) {
		node = &model->parser->node_seq.buffer[i];
		model->nodeinfo = g_list_append(model->nodeinfo, node);
	}
	
	model->nodeinfo = g_list_sort(model->nodeinfo, compare_node_func);
	
	cur = xmlDocGetRootElement(xmldoc);

    if ((IS_XSLT_ELEM(cur)) &&
		((IS_XSLT_NAME(cur, "stylesheet")) ||
		(IS_XSLT_NAME(cur, "transform")))) {
		xsldoc = xsltParseStylesheetDoc(xmldoc);
	} else {
		xsldoc = NULL;
	}

	if(model->xsldoc != NULL) {
		xsltFreeStylesheet(model->xsldoc);
		model->xmldoc = NULL;
	}
	
	if(model->xmldoc)
		xmlFreeDoc(model->xmldoc);

	model->xmldoc = xmldoc;
	model->xsldoc = xsldoc;
	model->filename = filename;
	model->stamp = g_random_int();  /* Random int to check whether an iter belongs to our model */

	gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
	gtk_tree_model_row_changed(GTK_TREE_MODEL(model),gtk_tree_path_new_first(), &iter);
	
	g_signal_emit(model, xml_tree_model_signals[XML_TREE_MODEL_CHANGED],0,NULL);
	
    //xmlFreeParserCtxt(model->parser);
}