From 01e109668eff8554ec7ecc1549112b29d273033f Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 12 Aug 2005 16:46:16 +0000 Subject: [PATCH] added some test code to xmltools. git-svn-id: svn://svn.open-ils.org/ILS/trunk@1650 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/apachemods/Makefile | 2 +- Open-ILS/src/apachemods/xmltools.c | 31 +++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/apachemods/Makefile b/Open-ILS/src/apachemods/Makefile index 5f39230216..2ef57e0bed 100644 --- a/Open-ILS/src/apachemods/Makefile +++ b/Open-ILS/src/apachemods/Makefile @@ -3,7 +3,7 @@ #APXS2 = /home/erickson/sandbox/apache2/bin/apxs # --------------------------------------------------------------------------------- -LD_OPTS += -lxml2 -lc_utils +LD_OPTS += -lxml2 -lc_utils -lxslt all: mod_xmltools.so diff --git a/Open-ILS/src/apachemods/xmltools.c b/Open-ILS/src/apachemods/xmltools.c index e2b9cb3b39..6f0b6e4519 100644 --- a/Open-ILS/src/apachemods/xmltools.c +++ b/Open-ILS/src/apachemods/xmltools.c @@ -8,13 +8,14 @@ int main(int argc, char* argv[]) { char* file = argv[1]; char* dtdfile = argv[2]; - xmlDocPtr doc; + printf("\n%s\n", xmlDocToString(xmlParseEntity(file), 1)); - /* - xmlSubstituteEntitiesDefault(0); + xmlDocPtr doc; + + xmlSubstituteEntitiesDefault(1); xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); - doc = xmlCtxtReadFile(ctxt, file, NULL, XML_PARSE_NOENT | XML_PARSE_RECOVER | XML_PARSE_XINCLUDE | XML_PARSE_NOERROR | XML_PARSE_NOWARNING ); + doc = xmlCtxtReadFile(ctxt, file, NULL, XML_PARSE_NOENT | XML_PARSE_RECOVER | XML_PARSE_NOERROR | XML_PARSE_NOWARNING ); if(doc != NULL) fprintf(stderr, "What we have so far:\n%s\n", xmlDocToString(doc, 1)); else { @@ -22,15 +23,14 @@ int main(int argc, char* argv[]) { return 0; } - exit(99); - */ - /* parse the doc */ + /* if( (doc = xmlParseFile(file)) == NULL) { fprintf(stderr, "\n ^-- Error parsing XML file %s\n", file); fflush(stderr); return 99; } + */ /* process xincludes */ if( xmlXIncludeProcessFlags(doc, XML_PARSE_NOENT) < 0 ) { @@ -42,12 +42,23 @@ int main(int argc, char* argv[]) { } + /* replace the DTD */ + /* if(xmlReplaceDtd(doc, dtdfile) < 0) { fprintf(stderr, "Error replacing DTD file with file %s\n", dtdfile); fflush(stderr); return 99; } + */ + + // + xmlAddDocEntity(doc, "test", XML_INTERNAL_GENERAL_ENTITY, NULL, NULL, "Here is my test"); + + xmlSubstituteEntitiesDefault(1); + printf("---------------------------------\n%s\n", xmlDocToString(doc,1)); + exit(99); + // /* force DTD entity replacement */ doc = xmlProcessDtdEntities(doc); @@ -58,7 +69,6 @@ int main(int argc, char* argv[]) { fprintf(stderr, "%s\n", xml); /* deallocate */ - free(dtdfile); free(xml); xmlFreeDoc(doc); xmlCleanupCharEncodingHandlers(); @@ -112,6 +122,8 @@ int xmlReplaceDtd(xmlDocPtr doc, char* dtdfile) { char* xmlDocToString(xmlDocPtr doc, int full) { + if(!doc) return NULL; + char* xml; if(full) { @@ -132,5 +144,6 @@ char* xmlDocToString(xmlDocPtr doc, int full) { return xml; } - } + + -- 2.43.2