From c2965a751d80cc8d4949eb68970a693b418f826b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 25 Mar 2012 13:56:41 +0000 Subject: Implement html_document_get_forms svn path=/trunk/libdom/; revision=13687 --- src/html/html_document.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/html/html_document.c b/src/html/html_document.c index 52c6eca..607bbaf 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -10,6 +10,7 @@ #include "html/html_document.h" #include "html/html_element.h" +#include "html/html_collection.h" #include "core/string.h" #include "utils/namespace.h" @@ -309,13 +310,48 @@ dom_exception _dom_html_document_get_links(dom_html_document *doc, return DOM_NOT_SUPPORTED_ERR; } +static bool __dom_html_document_node_is_form(dom_node_internal *node) +{ + dom_string *form; + dom_exception err; + + err = dom_string_create_interned((const uint8_t *) "form", + SLEN("form"), &form); + if (err == DOM_NO_ERR) { + if (dom_string_caseless_isequal(node->name, form)) { + dom_string_unref(form); + return true; + } + + dom_string_unref(form); + } + + return false; +} + dom_exception _dom_html_document_get_forms(dom_html_document *doc, struct dom_html_collection **col) { - UNUSED(doc); - UNUSED(col); + dom_html_collection *result; + dom_element *root; + dom_exception err; - return DOM_NOT_SUPPORTED_ERR; + err = dom_document_get_document_element(doc, &root); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_collection_create(doc, (dom_node_internal *) root, + __dom_html_document_node_is_form, &result); + if (err != DOM_NO_ERR) { + dom_node_unref(root); + return err; + } + + dom_node_unref(root); + + *col = result; + + return DOM_NO_ERR; } dom_exception _dom_html_document_get_anchors(dom_html_document *doc, -- cgit v1.2.3