+}
+
+static void
+print_attributes (xmlNode * a_node)
+{
+ for (xmlNode *node = a_node; node; node = node->next)
+ {
+ if (node->type == XML_ELEMENT_NODE)
+ {
+ printf ("%s", node->name);
+ for (xmlAttr *attr = node->properties; attr; attr = attr->next)
+ printf (" %s", attr->name);
+ putchar ('\n');
+ }
+
+ print_attributes (node->children);
+ }
+}
+
+static void
+print_string(xmlChar *s)
+{
+ for (char *p = (char *) s; *p; p++)
+ if (*p == '\n')
+ printf ("\\n");
+ else
+ putchar (*p);
+}
+
+static void
+print_cdata (xmlNode * a_node)
+{
+ for (xmlNode *node = a_node; node; node = node->next)
+ {
+ if (node->type == XML_CDATA_SECTION_NODE)
+ {
+ print_string (node->content);
+ putchar ('\n');
+ }
+
+ print_cdata (node->children);
+ }
+}
+
+static void
+print_attribute (xmlNode *node, const char *attr)
+{
+ for (; node; node = node->next)
+ {
+ const char *s = (char *) xmlGetProp (node, (xmlChar *) attr);
+ if (s)
+ printf ("%s %s=%s\n", node->name, attr, s);
+
+ print_attribute (node->children, attr);
+ }
+}
+
+static __attribute__((unused)) xmlNode *
+find_page_setup (xmlNode *node)
+{
+ for (; node; node = node->next)
+ {
+ if (node->name && !strcmp ((char *) node->name, "pageSetup"))
+ return node;
+
+ xmlNode *ps = find_page_setup (node->children);
+ if (ps)
+ return ps;
+ }
+ return NULL;
+}
+
+static void
+print_text (xmlNode *node)
+{
+ for (; node; node = node->next)
+ {
+ if (node->type == XML_ELEMENT_NODE)
+ {
+ printf ("%s", node->name);
+ for (xmlNode *child = node->children; child; child = child->next)
+ if (child->type == XML_TEXT_NODE)
+ {
+ putchar (' ');
+ print_string (child->content);
+ }
+ putchar ('\n');
+ }
+
+ print_text (node->children);
+ }
+}
+
+static void
+usage (void)
+{
+ fprintf (stderr, "usage: parse-xml FILE.xml containment|attributes\n");
+ exit (1);
+}
+
+int
+main (int argc, char **argv)
+{
+ if (argc != 3)
+ usage ();