summaryrefslogtreecommitdiff
path: root/misc/samples/xml_dom.c
diff options
context:
space:
mode:
authorManuel Traut <manut@mecka.net>2013-03-10 12:13:49 +0100
committerManuel Traut <manut@mecka.net>2013-03-10 12:13:49 +0100
commit9c0f862749f30800837a45aff5abdcb529867dbc (patch)
treeb0ca51fff64f12fac03aea4afaa1fa722376844b /misc/samples/xml_dom.c
parent33b79c725448efd2c9a72e2ae9a1fb04270492f5 (diff)
parentcea5039322781f6085dd47954af5584ca3f78911 (diff)
Merge branch 'schulung'
updates from current linutronix schulung.git Conflicts: Makefile configpres.tex flash-memory/ubi/handout_ubi_de.tex handout.tex index.txt pres_master.tex vorl.tex vorl1.tex vorl2.tex vorl3.tex vorl4.tex vorl5.tex Signed-off-by: Manuel Traut <manut@mecka.net>
Diffstat (limited to 'misc/samples/xml_dom.c')
-rw-r--r--misc/samples/xml_dom.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/misc/samples/xml_dom.c b/misc/samples/xml_dom.c
new file mode 100644
index 0000000..66166dd
--- /dev/null
+++ b/misc/samples/xml_dom.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+static void print_element_names(xmlNode *);
+
+int main(int argc, char **argv) {
+ xmlDocPtr my_doc = NULL;
+ xmlNode *root_element = NULL;
+ char *filename;
+ int rc = 1;
+
+ if (argc != 2) {
+ rc = 1;
+ goto out;
+ }
+ filename = argv[1];
+
+ /* ABI checking (opt.) */
+ LIBXML_TEST_VERSION
+
+ my_doc = xmlReadFile(filename, NULL, 0);
+ if (!my_doc) {
+ rc = 1;
+ goto out_cleanup;
+ }
+
+ /*Get the root element node */
+ root_element = xmlDocGetRootElement(my_doc);
+
+ print_element_names(root_element);
+
+ rc = 0;
+out_freedoc:
+ /* Free parsed DOM tree */
+ xmlFreeDoc(my_doc);
+out_cleanup:
+ /* Cleanup function for the XML library */
+ xmlCleanupParser();
+out:
+ return(rc);
+}
+
+static void print_element_names(xmlNode * a_node)
+{
+ xmlNode *cur_node = NULL;
+
+ for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
+ if (cur_node->type == XML_ELEMENT_NODE) {
+ printf("node type: Element, name: %s\n", cur_node->name);
+ }
+
+ print_element_names(cur_node->children);
+ }
+}