From f907092126ccfd1bfb825a99683b39237c482bbc Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 5 Dec 2010 16:47:34 +0000 Subject: Add commented out code for getting and dumping the class attribute. svn path=/trunk/dom/; revision=11007 --- examples/dom-structure-dump.c | 66 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/dom-structure-dump.c b/examples/dom-structure-dump.c index 4e7f77c..ee4830f 100644 --- a/examples/dom-structure-dump.c +++ b/examples/dom-structure-dump.c @@ -138,6 +138,67 @@ dom_document *create_doc_dom_from_file(char *file) } +/** + * Dump class attribute/value for an element node + * + * \param node The element node to dump class for + * \return true on success, or false on error + */ +bool dump_dom_element_class(dom_node_internal *node) +{ + dom_exception exc; + lwc_error err; + dom_string *class = NULL; + dom_string *classvalue = NULL; + lwc_string *lwcstr = NULL; + dom_node_type type; + int i; + const char *string; + size_t length; + + /* 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"); + return false; + } + assert(type == DOM_ELEMENT_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"); + 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"); + return false; + } else if (classvalue == NULL) { + /* Element has no class attribute */ + return true; + } + + /* 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"); + return false; + } + + /* Get string data and print class info */ + string = lwc_string_data(lwcstr); + length = lwc_string_length(lwcstr); + printf(" class=\"%*s\"", length, string); + + /* Print the element's class, if it has one */ + dump_dom_element_class(node); + return true; +} + + /** * Print a line in a DOM structure dump for an element * @@ -196,7 +257,10 @@ bool dump_dom_element(dom_node_internal *node, int depth) length = lwc_string_length(lwcstr); printf("%*s", length, string); - /* TODO: Print the element's class, if it has one */ + /* PENDING FIX: Print the element's class, if it has one */ +// if (dump_dom_element_class(node) == false) { +// return false; +// } printf("\n"); return true; -- cgit v1.2.3