diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2010-12-08 16:29:01 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2010-12-08 16:29:01 +0000 |
commit | f573aae1217a6cd54de633d4815eb20c34c0875e (patch) | |
tree | 793f288558c88b469b9104433c71cb45d1fdfafa /examples | |
parent | b79bcc3fef8a90c96b3db8dcb34ceea0f778e876 (diff) | |
download | libdom-f573aae1217a6cd54de633d4815eb20c34c0875e.tar.gz libdom-f573aae1217a6cd54de633d4815eb20c34c0875e.tar.bz2 |
Enable the class dumping code, but it gives up cleanly on the first class encountered because of a NULL lwc_string.
svn path=/trunk/libdom/; revision=11027
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dom-structure-dump.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/examples/dom-structure-dump.c b/examples/dom-structure-dump.c index b7eb8df..4f44319 100644 --- a/examples/dom-structure-dump.c +++ b/examples/dom-structure-dump.c @@ -159,7 +159,7 @@ bool dump_dom_element_class(dom_node_internal *node) /* Should only have element nodes here */ exc = dom_node_get_node_type(node, &type); if (exc != DOM_NO_ERR) { - printf("Exception raised for node_get_node_type\n"); + printf(" Exception raised for node_get_node_type\n"); return false; } assert(type == DOM_ELEMENT_NODE); @@ -167,14 +167,14 @@ bool dump_dom_element_class(dom_node_internal *node) /* Create a dom_string constaining "class". */ exc = dom_string_create(test_realloc, NULL, "class", 5, &class); if (exc != DOM_NO_ERR) { - printf("Exception raised for dom_string_create\n"); + printf(" Exception raised for dom_string_create\n"); return false; } /* Get class attribute's value */ exc = dom_element_get_attribute(node, class, &classvalue); if (exc != DOM_NO_ERR) { - printf("Exception raised for element_get_attribute\n"); + printf(" Exception raised for element_get_attribute\n"); return false; } else if (classvalue == NULL) { /* Element has no class attribute */ @@ -184,7 +184,10 @@ bool dump_dom_element_class(dom_node_internal *node) /* Get attributes's lwc_string */ exc = dom_string_get_intern(classvalue, &lwcstr); if (exc != DOM_NO_ERR) { - printf("Exception raised for string_get_intern\n"); + printf(" Exception raised for string_get_intern\n"); + return false; + } else if (lwcstr == NULL) { + printf(" Broken: lwcstr == NULL\n"); return false; } @@ -264,9 +267,9 @@ bool dump_dom_element(dom_node_internal *node, int depth) printf("%*s", length, string); /* PENDING FIX: Print the element's class, if it has one */ -// if (dump_dom_element_class(node) == false) { -// return false; -// } + if (dump_dom_element_class(node) == false) { + return false; + } printf("\n"); return true; @@ -302,7 +305,10 @@ bool dump_dom_structure(dom_node_internal *node, int depth) /* Loop though all node's children */ do { /* Visit node's descendents */ - dump_dom_structure(child, depth); + if (dump_dom_structure(child, depth) == false) { + /* There was an error; return */ + return false; + } /* Go to next sibling */ exc = dom_node_get_next_sibling(child, &child); @@ -353,6 +359,7 @@ int main(int argc, char **argv) /* Dump DOM structure */ if (dump_dom_structure(root, 0) == false) { + printf("Failed to complete DOM structure dump.\n"); return EXIT_FAILURE; } @@ -363,6 +370,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + /* Finished with the dom_document */ + dom_node_unref(doc); + return EXIT_SUCCESS; } |