2 #include "http_config.h"
4 #include "http_protocol.h"
5 #include "apr_compat.h"
6 #include "apr_strings.h"
8 #include <libxml/parser.h>
9 #include <libxml/xinclude.h>
11 #define MODULE_NAME "xinclude_module"
13 static int mod_xinclude_handler (request_rec *r) {
15 /* make sure we're needed first thing*/
16 if (strcmp(r->handler, MODULE_NAME ))
19 /* set content type */
20 ap_set_content_type(r, "text/html");
23 /* which file are we parsing */
24 char* file = r->filename;
27 fprintf(stderr, "No XML file to parse");
29 return HTTP_INTERNAL_SERVER_ERROR;
33 xmlDocPtr doc = xmlParseFile(file);
36 fprintf(stderr, "Error parsing XML file %s\n", file);
38 return HTTP_INTERNAL_SERVER_ERROR;
41 /* process the xincludes */
42 int status = xmlXIncludeProcess(doc);
45 fprintf(stderr, "Error processing XIncludes in XML file %s\n", file);
47 return HTTP_INTERNAL_SERVER_ERROR;
50 xmlBufferPtr xmlbuf = xmlBufferCreate();
51 xmlNodeDump( xmlbuf, doc, xmlDocGetRootElement(doc), 0, 0);
52 char* xml = (char*) (xmlBufferContent(xmlbuf));
56 xmlBufferFree(xmlbuf);
63 static void mod_xinclude_register_hooks (apr_pool_t *p) {
64 ap_hook_handler(mod_xinclude_handler, NULL, NULL, APR_HOOK_MIDDLE);
67 module AP_MODULE_DECLARE_DATA xinclude_module = {
68 STANDARD20_MODULE_STUFF,
74 mod_xinclude_register_hooks,