+ if (node->type == XML_ELEMENT_NODE
+ && !strcmp((char *) node->name, "label")
+ && node->parent->type == XML_ELEMENT_NODE
+ && !strcmp((char *) node->parent->name, "container"))
+ {
+ for (xmlNode *child = node->children; child; child = child->next)
+ if (child->type == XML_TEXT_NODE)
+ puts ((char *) child->content);
+ }
+
+ print_labels (node->children);
+ }
+}
+
+static int
+compare_strings(const void *a_, const void *b_)
+{
+ const void *const *ap = a_;
+ const void *const *bp = b_;
+ return strcmp (*ap, *bp);
+}
+
+static void
+print_attributes (xmlNode * a_node)
+{
+ for (xmlNode *node = a_node; node; node = node->next)
+ {
+ if (node->type == XML_ELEMENT_NODE)
+ {
+ printf ("%s<-%s", node->name, node->parent->name);
+
+ char *attrs[500];
+ int n_attrs = 0;
+ for (xmlAttr *attr = node->properties; attr; attr = attr->next)
+ if (!strcmp((char *) attr->name, "baseFormat"))
+ printf(" baseFormat=%s", attr->children->content);
+ else
+ attrs[n_attrs++] = (char *) attr->name;
+ qsort(attrs, n_attrs, sizeof *attrs, compare_strings);
+
+ for (int i = 0; i < n_attrs; i++)
+ printf (" %s", attrs[i]);
+ 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 void
+print_element (xmlDoc *doc, xmlNode *node, const char *element)
+{
+ for (; node; node = node->next)
+ {
+ if (!strcmp(element, (char *) node->name))
+ {
+ xmlBuffer *buf = xmlBufferCreate();
+ xmlNodeDump (buf, doc, node, 0, 1);
+ xmlBufferDump (stdout, buf);
+ xmlBufferFree (buf);
+ putchar ('\n');
+ }
+
+ print_element (doc, node->children, element);
+ }
+}
+
+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);