examples/libxml.c
error_code create_context(const char *charset, context **ctx)
{
	context *c;
	hubbub_parser_optparams params;
	uint32_t i;
	hubbub_error error;

	c = malloc(sizeof(context));
	if (c == NULL)
		return NOMEM;

	c->parser = NULL;
	c->encoding = charset;
	c->enc_source = ENCODING_SOURCE_HEADER;
	c->document = NULL;

	/* Create the parser */
	error = hubbub_parser_create(c->encoding, true, myrealloc, NULL, 
			&c->parser);
	if (error != HUBBUB_OK) {
		free(c);
		if (error == HUBBUB_BADENCODING)
			return BADENCODING;
		else
			return NOMEM;	/* Assume OOM */
	}

	/* Create the root node of the document */
	c->document = htmlNewDocNoDtD(NULL, NULL);
	if (c->document == NULL) {
		hubbub_parser_destroy(c->parser);
		free(c);
		return NOMEM;
	}
	/* Reference count of zero */
	c->document->_private = (void *) 0;

	for (i = 0; 
		i < sizeof(c->namespaces) / sizeof(c->namespaces[0]); i++) {
		c->namespaces[i] = NULL;
	}

	/* The following are both needed to make hubbub do anything. If it has 
	 * no tree handler or document node registered, it won't attempt to 
	 * build a tree. */

	/* Register tree handler with hubbub */
	c->tree_handler = tree_handler;
	c->tree_handler.ctx = (void *) c;

	params.tree_handler = &c->tree_handler;
	hubbub_parser_setopt(c->parser, HUBBUB_PARSER_TREE_HANDLER, &params);

	/* Also tell it about the document node (referencing it first) */
	ref_node(c, c->document);
	params.document_node = c->document;
	hubbub_parser_setopt(c->parser, HUBBUB_PARSER_DOCUMENT_NODE, &params);

	*ctx = c;

	return OK;
}
/**
 * Create a parsing context
 *
 * \param charset  The charset the input data is in, or NULL to autodetect
 * \param ctx      Location to receive context
 * \return OK on success, 
 *         NOMEM on memory exhaustion, 
 *         BADENCODING if charset isn't supported
 */
Create a parsing context
\param charset  The charset the input data is in, or NULL to autodetect
\param ctx      Location to receive context
\return OK on success,
NOMEM on memory exhaustion,
BADENCODING if charset isn't supported
Create a parsing context \ param charset The charset the input data is in or NULL to autodetect \ param ctx Location to receive context \ return OK on success NOMEM on memory exhaustion BADENCODING if charset isn ' t supported
error_code create_context(const char *charset, context **ctx)
{
	context *c;
	hubbub_parser_optparams params;
	uint32_t i;
	hubbub_error error;
	c = malloc(sizeof(context));
	if (c == NULL)
		return NOMEM;
	c->parser = NULL;
	c->encoding = charset;
	c->enc_source = ENCODING_SOURCE_HEADER;
	c->document = NULL;
	error = hubbub_parser_create(c->encoding, true, myrealloc, NULL, 
			&c->parser);
	if (error != HUBBUB_OK) {
		free(c);
		if (error == HUBBUB_BADENCODING)
			return BADENCODING;
		else
			return NOMEM;	
	}
	c->document = htmlNewDocNoDtD(NULL, NULL);
	if (c->document == NULL) {
		hubbub_parser_destroy(c->parser);
		free(c);
		return NOMEM;
	}
	c->document->_private = (void *) 0;
	for (i = 0; 
		i < sizeof(c->namespaces) / sizeof(c->namespaces[0]); i++) {
		c->namespaces[i] = NULL;
	}
	c->tree_handler = tree_handler;
	c->tree_handler.ctx = (void *) c;
	params.tree_handler = &c->tree_handler;
	hubbub_parser_setopt(c->parser, HUBBUB_PARSER_TREE_HANDLER, &params);
	ref_node(c, c->document);
	params.document_node = c->document;
	hubbub_parser_setopt(c->parser, HUBBUB_PARSER_DOCUMENT_NODE, &params);
	*ctx = c;
	return OK;
}
error_code create_context ( const char * charset , context * * ctx ) { context * c ; hubbub_parser_optparams params ; uint32_t i ; hubbub_error error ; c = malloc ( sizeof ( context ) ) ; if ( c == NULL ) return NOMEM ; c -> parser = NULL ; c -> encoding = charset ; c -> enc_source = ENCODING_SOURCE_HEADER ; c -> document = NULL ; error = hubbub_parser_create ( c -> encoding , true , myrealloc , NULL , & c -> parser ) ; if ( error != HUBBUB_OK ) { free ( c ) ; if ( error == HUBBUB_BADENCODING ) return BADENCODING ; else return NOMEM ; } c -> document = htmlNewDocNoDtD ( NULL , NULL ) ; if ( c -> document == NULL ) { hubbub_parser_destroy ( c -> parser ) ; free ( c ) ; return NOMEM ; } c -> document -> _private = ( void * ) 0 ; for ( i = 0 ; i < sizeof ( c -> namespaces ) / sizeof ( c -> namespaces [ 0 ] ) ; i ++ ) { c -> namespaces [ i ] = NULL ; } c -> tree_handler = tree_handler ; c -> tree_handler . ctx = ( void * ) c ; params . tree_handler = & c -> tree_handler ; hubbub_parser_setopt ( c -> parser , HUBBUB_PARSER_TREE_HANDLER , & params ) ; ref_node ( c , c -> document ) ; params . document_node = c -> document ; hubbub_parser_setopt ( c -> parser , HUBBUB_PARSER_DOCUMENT_NODE , & params ) ; * ctx = c ; return OK ; }
Create a parsing context
 \param charset  The charset the input data is in, or NULL to autodetect
 \param ctx      Location to receive context
 \return OK on success,
         NOMEM on memory exhaustion,
         BADENCODING if charset isn't supported
Create a parsing context \ param charset The charset the input data is in or NULL to autodetect \ param ctx Location to receive context \ return OK on success NOMEM on memory exhaustion BADENCODING if charset isn ' t supported
/* Create the parser */ /* Assume OOM */ /* Create the root node of the document */ /* Reference count of zero */ /* The following are both needed to make hubbub do anything. If it has 
	 * no tree handler or document node registered, it won't attempt to 
	 * build a tree. */ /* Register tree handler with hubbub */ /* Also tell it about the document node (referencing it first) */