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");
28 return HTTP_INTERNAL_SERVER_ERROR;
32 xmlDocPtr doc = xmlParseFile(file);
35 fprintf(stderr, "Error parsing XML file %s\n", file);
36 return HTTP_INTERNAL_SERVER_ERROR;
39 /* process the xincludes */
40 int status = xmlXIncludeProcess(doc);
43 fprintf(stderr, "Error processing XIncludes in XML file %s\n", file);
44 return HTTP_INTERNAL_SERVER_ERROR;
47 xmlBufferPtr xmlbuf = xmlBufferCreate();
48 xmlNodeDump( xmlbuf, doc, xmlDocGetRootElement(doc), 0, 0);
49 char* xml = (char*) (xmlBufferContent(xmlbuf));
53 xmlBufferFree(xmlbuf);
60 static void mod_xinclude_register_hooks (apr_pool_t *p) {
61 ap_hook_handler(mod_xinclude_handler, NULL, NULL, APR_HOOK_MIDDLE);
64 module AP_MODULE_DECLARE_DATA xinclude_module = {
65 STANDARD20_MODULE_STUFF,
71 mod_xinclude_register_hooks,