Subversion Repositories Kolibri OS

Rev

Rev 4364 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19.  
  20. /** \file
  21.  * libdom utilities (implementation).
  22.  */
  23.  
  24. #ifndef NETSURF_UTILS_LIBDOM_H_
  25. #define NETSURF_UTILS_LIBDOM_H_
  26.  
  27. #include <stdbool.h>
  28.  
  29. #include <dom/dom.h>
  30.  
  31. #include <libdom/bindings/hubbub/parser.h>
  32. #include <libdom/bindings/hubbub/errors.h>
  33.  
  34. /**
  35.  * depth-first walk the dom calling callback for each element
  36.  *
  37.  * \param root the dom node to use as the root of the tree walk
  38.  * \return true if all nodes were examined, false if the callback terminated
  39.  *         the walk early.
  40.  */
  41. bool libdom_treewalk(dom_node *root,
  42.                 bool (*callback)(dom_node *node, dom_string *name, void *ctx),
  43.                 void *ctx);
  44.  
  45. /**
  46.  * Search the descendants of a node for an element.
  47.  *
  48.  * \param  node         dom_node to search children of, or NULL
  49.  * \param  element_name name of element to find
  50.  * \return  first child of node which is an element and matches name, or
  51.  *          NULL if not found or parameter node is NULL
  52.  */
  53. dom_node *libdom_find_element(dom_node *node, lwc_string *element_name);
  54.  
  55. /**
  56.  * Search children of a node for first named element
  57.  * \param  parent dom_node to search children of, or NULL
  58.  * \param  element_name name of element to find
  59.  * \return  first child of node which is an element and matches name, or
  60.  *          NULL if not found or parameter node is NULL
  61.  */
  62. dom_node *libdom_find_first_element(dom_node *parent, lwc_string *element_name);
  63.  
  64. typedef bool (*libdom_iterate_cb)(dom_node *node, void *ctx);
  65.  
  66. void libdom_iterate_child_elements(dom_node *parent,
  67.                 libdom_iterate_cb cb, void *ctx);
  68.  
  69. nserror libdom_parse_file(const char *filename, const char *encoding,
  70.                 dom_document **doc);
  71.  
  72. /**
  73.  * Convert libdom hubbub binding errors to nserrors.
  74.  *
  75.  * \param error The hubbub binding error to convert
  76.  * \return The appropriate nserror
  77.  */
  78. nserror libdom_hubbub_error_to_nserror(dom_hubbub_error error);
  79.  
  80. #endif
  81.