From 9122bfd1dbbb4489b70f3c13e24daa29ef630973 Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 28 Apr 2009 16:47:48 +0000 Subject: [PATCH] * add printxml, an example utility that walks an xml-tree and prints it contenst --- utils/xmlgrep/ChangeLog | 2 + utils/xmlgrep/Makefile.am | 4 +- utils/xmlgrep/printxml.c | 89 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 utils/xmlgrep/printxml.c diff --git a/utils/xmlgrep/ChangeLog b/utils/xmlgrep/ChangeLog index d7b5b37f6..be6926431 100644 --- a/utils/xmlgrep/ChangeLog +++ b/utils/xmlgrep/ChangeLog @@ -1,5 +1,7 @@ 28-04-2009 * changes to the code to allow walking the xml-tree using "*" as a node name + * add printxml, an example utility that walks an xml-tree and prints it + contenst 27-04-2009 * add xmlInitBuffer() for processing of a preallocated buffer diff --git a/utils/xmlgrep/Makefile.am b/utils/xmlgrep/Makefile.am index cd314d4d8..160aca75d 100644 --- a/utils/xmlgrep/Makefile.am +++ b/utils/xmlgrep/Makefile.am @@ -1,3 +1,5 @@ -noinst_PROGRAMS = xmlgrep +noinst_PROGRAMS = xmlgrep printxml xmlgrep_SOURCES = xmlgrep.c xml.c xml.h + +printxml_SOURCES = printxml.c xml.c diff --git a/utils/xmlgrep/printxml.c b/utils/xmlgrep/printxml.c new file mode 100644 index 000000000..c35f7f1b5 --- /dev/null +++ b/utils/xmlgrep/printxml.c @@ -0,0 +1,89 @@ + +#include +#include +#include "xml.h" + +void print_xml(void *); + +int main(int argc, char **argv) +{ + if (argc < 1) + { + printf("usage: printxml \n\n"); + } + else + { + void *rid; + + rid = xmlOpen(argv[1]); + if (rid) + { + unsigned int i, num; + void *xid; + + xid = xmlMarkId(rid); + num = xmlNodeGetNum(xid, "*"); + for (i=0; i\n", name); + print_xml(xid); + printf("\n\n", name); + } + } + free(xid); + + xmlClose(rid); + } + else + { + printf("Error while opening file for reading: '%s'\n", argv[1]); + } + } +} + +void print_xml(void *id) +{ + static int level = 1; + void *xid = xmlMarkId(id); + unsigned int i, num; + + num = xmlNodeGetNum(xid, "*"); + if (num == 0) + { + char value[256]; + int q; + + q = xmlCopyString(xid, (char *)&value, 256); + if (q) printf("%s", value); + } + else + { + unsigned int i, q; + for (i=0; i", name); + + level++; + print_xml(xid); + level--; + + printf("", name); + } + else printf("error\n"); + } + printf("\n"); + for(q=1; q