/* sudo apt-get install libxml2-dev */ /* gcc -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wextra $(xml2-config --cflags) -DPIC -fPIC -shared -o libforceXHTML.so forceXHTML.c */ /* LD_PRELOAD=$PWD/libforceXHTML.so xmlstarlet fo [-n] [-e encoding] filename|- */ /* do not use the xmlstarlet fo -o option! */ #include #include #include #include static int rpl_xmlSaveFormatFileEnc(const char *filename, xmlDocPtr cur, const char *encoding) { xmlSaveCtxtPtr ctx; int i; if (!encoding) encoding = (const void *)cur->encoding; i = XML_SAVE_XHTML; if (xmlIndentTreeOutput) i |= XML_SAVE_FORMAT; ctx = xmlSaveToFilename(filename, encoding, i); if (!ctx) return (-1); i = xmlSaveDoc(ctx, cur); /* fucking libxml2 API gives us no way to check close() errors */ if (i >= 0) i = xmlSaveClose(ctx); else xmlSaveClose(ctx); fprintf(stderr, "\nI: forceXHTML save %s\n", i < 0 ? "failed" : "ok"); return (i); } int xmlSaveFormatFileEnc(const char *filename, xmlDocPtr cur, const char *encoding, int format __attribute__((__unused__))) { return (rpl_xmlSaveFormatFileEnc(filename, cur, encoding)); } int xmlSaveFormatFile(const char *filename, xmlDocPtr cur, int format __attribute__((__unused__))) { return (rpl_xmlSaveFormatFileEnc(filename, cur, NULL)); }