4 #include <libxml/parser.h>
5 #include <libxml/tree.h>
8 * File boundaries are dive boundaries. But sometimes there are
9 * multiple dives per file, so there can be other events too that
10 * trigger a "new dive" marker and you may get some nesting due
11 * to that. Just ignore nesting levels.
13 static void dive_start(void)
18 static void dive_end(void)
22 static void sample_start(void)
27 static void sample_end(void)
31 static void entry(const char *name, int size, const char *buffer)
33 printf("%s: %.*s\n", name, size, buffer);
36 static const char *nodename(xmlNode *node, char *buf, int len)
38 /* Don't print out the node name if it is "text" */
39 if (!strcmp(node->name, "text")) {
41 if (!node || !node->name)
50 const char *name = node->name;
53 unsigned char c = name[i];
59 if (!node || !node->name)
69 static void visit_one_node(xmlNode *node)
72 const unsigned char *content;
76 content = node->content;
80 /* Trim whitespace at beginning */
81 while (isspace(*content))
84 /* Trim whitespace at end */
85 len = strlen(content);
86 while (len && isspace(content[len-1]))
92 name = nodename(node, buffer, sizeof(buffer));
94 entry(name, len, content);
97 static void traverse(xmlNode *node)
101 for (n = node; n; n = n->next) {
102 /* XML from libdivecomputer: 'dive' per new dive */
103 if (!strcmp(n->name, "dive")) {
105 traverse(n->children);
111 * At least both libdivecomputer and Suunto
114 * Well - almost. Ignore case.
116 if (!strcasecmp(n->name, "sample")) {
118 traverse(n->children);
123 /* Anything else - just visit it and recurse */
125 traverse(n->children);
129 static void parse(const char *filename)
133 doc = xmlReadFile(filename, NULL, 0);
135 fprintf(stderr, "Failed to parse '%s'.\n", filename);
140 traverse(xmlDocGetRootElement(doc));
146 int main(int argc, char **argv)
152 for (i = 1; i < argc; i++)