-dump.o: CFLAGS = -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1
-dump2.o: CFLAGS = -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1 -Wno-unused
-all: dump dump2
+CFLAGS := -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1
+base_cflags := $(CFLAGS)
+base_ldflags := $(LDFLAGS)
+parse-xml.o: CFLAGS := $(shell pkg-config --cflags libxml-2.0) $(base_cflags)
+parse-xml: LDFLAGS := $(shell pkg-config --libs libxml-2.0) $(LDFLAGS)
+dump2.o: CFLAGS := $(base_cflags) -Wno-unused
+
+all: dump dump2 parse-xml
dump: dump.o
dump2: dump2.o
+parse-xml: parse-xml.o
--- /dev/null
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+static void
+print_containment (xmlNode * a_node)
+{
+ for (xmlNode *node = a_node; node; node = node->next)
+ {
+ if (node->type == XML_ELEMENT_NODE)
+ {
+ const xmlNode *parent = node->parent;
+ if (parent->type == XML_ELEMENT_NODE)
+ printf ("%s %s\n", parent->name, node->name);
+ else if (parent->type == XML_DOCUMENT_NODE)
+ printf ("<root> %s\n", node->name);
+ }
+
+ print_containment (node->children);
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ fprintf (stderr, "usage: %s FILE.xml\n", argv[0]);
+ exit (1);
+ }
+
+ LIBXML_TEST_VERSION;
+
+ xmlDoc *doc = xmlReadFile(argv[1], NULL, 0);
+ if (doc == NULL)
+ {
+ fprintf (stderr, "error: could not parse file %s\n", argv[1]);
+ exit (1);
+ }
+
+ xmlNode *root = xmlDocGetRootElement(doc);
+ print_containment(root);
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
+
+ return 0;
+}