38 dom_node_type node_type;
41 exc = dom_node_get_first_child(
parent, &element);
42 if ((exc != DOM_NO_ERR) || (element == NULL)) {
48 exc = dom_node_get_node_type(element, &node_type);
50 if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
51 exc = dom_node_get_node_name(element, &
node_name);
52 if ((exc == DOM_NO_ERR) && (
node_name != NULL)) {
53 if (dom_string_caseless_lwc_isequal(
node_name,
62 exc = dom_node_get_next_sibling(element, &
next_node);
63 dom_node_unref(element);
64 if (exc == DOM_NO_ERR) {
69 }
while (element != NULL);
79 dom_nodelist *children;
80 uint32_t index, num_children;
83 error = dom_node_get_child_nodes(
parent, &children);
84 if (error != DOM_NO_ERR || children == NULL)
87 error = dom_nodelist_get_length(children, &num_children);
88 if (error != DOM_NO_ERR) {
89 dom_nodelist_unref(children);
93 for (index = 0; index < num_children; index++) {
97 error = dom_nodelist_item(children, index, &child);
98 if (error != DOM_NO_ERR) {
99 dom_nodelist_unref(children);
103 error = dom_node_get_node_type(child, &
type);
104 if (error == DOM_NO_ERR &&
type == DOM_ELEMENT_NODE) {
107 dom_node_unref(child);
108 dom_nodelist_unref(children);
113 dom_node_unref(child);
116 dom_nodelist_unref(children);
134 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED):
138 case DOM_HUBBUB_NOMEM:
142 case DOM_HUBBUB_BADPARM:
150 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE):
154 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM):
158 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM):
161 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID):
164 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND):
167 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA):
170 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING):
173 case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
202 dom_string *attr = NULL;
203 dom_string *attr_value = NULL;
209 exc = dom_node_get_node_type(node, &
type);
210 if (exc != DOM_NO_ERR) {
211 fprintf(f,
" Exception raised for node_get_node_type\n");
214 assert(
type == DOM_ELEMENT_NODE);
217 exc = dom_string_create_interned((uint8_t *)attribute,
218 strlen(attribute), &attr);
219 if (exc != DOM_NO_ERR) {
220 fprintf(f,
" Exception raised for dom_string_create\n");
225 exc = dom_element_get_attribute(node, attr, &attr_value);
226 if (exc != DOM_NO_ERR) {
227 fprintf(f,
" Exception raised for element_get_attribute\n");
228 dom_string_unref(attr);
230 }
else if (attr_value == NULL) {
232 dom_string_unref(attr);
237 dom_string_unref(attr);
240 string = dom_string_data(attr_value);
241 length = dom_string_byte_length(attr_value);
244 fprintf(f,
" %s=\"%.*s\"", attribute, (
int)length,
string);
247 dom_string_unref(attr_value);
271 exc = dom_node_get_node_type(node, &
type);
272 if (exc != DOM_NO_ERR) {
273 fprintf(f,
"Exception raised for node_get_node_type\n");
275 }
else if (
type != DOM_ELEMENT_NODE) {
281 exc = dom_node_get_node_name(node, &
node_name);
282 if (exc != DOM_NO_ERR) {
283 fprintf(f,
"Exception raised for get_node_name\n");
286 fprintf(f,
"Broken: root_name == NULL\n");
292 for (i = 0; i < depth; i++) {
300 length = dom_string_byte_length(
node_name);
301 fprintf(f,
"[%.*s]", (
int)length,
string);
303 if (length == 5 && strncmp(
string,
"title", 5) == 0) {
306 exc = dom_node_get_text_content(node, &str);
307 if (exc == DOM_NO_ERR && str != NULL) {
308 fprintf(f,
" $%.*s$", (
int)dom_string_byte_length(str),
309 dom_string_data(str));
310 dom_string_unref(str);
336 dom_node *next_child;
345 exc = dom_node_get_first_child(node, &child);
346 if (exc != DOM_NO_ERR) {
347 fprintf(f,
"Exception raised for node_get_first_child\n");
349 }
else if (child != NULL) {
359 dom_node_unref(child);
364 exc = dom_node_get_next_sibling(child, &next_child);
365 if (exc != DOM_NO_ERR) {
366 fprintf(f,
"Exception raised for node_get_next_sibling\n");
367 dom_node_unref(child);
371 dom_node_unref(child);
373 }
while (child != NULL);
383 dom_hubbub_parser_params parse_params;
384 dom_hubbub_error error;
385 dom_hubbub_parser *parser;
386 dom_document *document;
391 fp = fopen(filename,
"r");
396 parse_params.enc = encoding;
397 parse_params.fix_enc =
false;
398 parse_params.enable_script =
false;
400 parse_params.script = NULL;
401 parse_params.ctx = NULL;
402 parse_params.daf = NULL;
404 error = dom_hubbub_parser_create(&parse_params, &parser, &document);
405 if (error != DOM_HUBBUB_OK) {
410 while (feof(fp) == 0) {
411 size_t read = fread(buf,
sizeof(buf[0]),
BUF_SIZE, fp);
413 error = dom_hubbub_parser_parse_chunk(parser, buf, read);
414 if (error != DOM_HUBBUB_OK) {
415 dom_node_unref(document);
416 dom_hubbub_parser_destroy(parser);
422 error = dom_hubbub_parser_completed(parser);
423 if (error != DOM_HUBBUB_OK) {
424 dom_node_unref(document);
425 dom_hubbub_parser_destroy(parser);
430 dom_hubbub_parser_destroy(parser);
static dom_node * next_node(dom_node *n, html_content *content, bool convert_children)
Find the next node in the DOM tree, completing element construction where appropriate.
nserror
Enumeration of error codes.
@ NSERROR_NOT_FOUND
Requested item not found.
@ NSERROR_BAD_ENCODING
The character set is unknown.
@ NSERROR_DOM
DOM call returned error.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_NEED_DATA
More data needed.
@ NSERROR_UNKNOWN
Unknown error - DO NOT USE.
@ NSERROR_ENCODING_CHANGE
The character changed.
@ NSERROR_INVALID
Invalid data.
@ NSERROR_NOMEM
Memory exhaustion.
nserror libdom_iterate_child_elements(dom_node *parent, libdom_iterate_cb cb, void *ctx)
dom_node * libdom_find_first_element(dom_node *parent, lwc_string *element_name)
Search children of a node for first named element.
nserror libdom_parse_file(const char *filename, const char *encoding, dom_document **doc)
static void ignore_dom_msg(uint32_t severity, void *ctx, const char *msg,...)
nserror libdom_hubbub_error_to_nserror(dom_hubbub_error error)
Convert libdom hubbub binding errors to nserrors.
nserror libdom_dump_structure(dom_node *node, FILE *f, int depth)
Walk though a DOM (sub)tree, in depth first order, printing DOM structure.
static bool dump_dom_element_attribute(dom_node *node, FILE *f, const char *attribute)
Dump attribute/value for an element node.
static bool dump_dom_element(dom_node *node, FILE *f, int depth)
Print a line in a DOM structure dump for an element.
libdom utilities (implementation).
nserror(* libdom_iterate_cb)(dom_node *node, void *ctx)
static css_error node_name(void *pw, void *node, css_qname *qname)
Callback to retrieve a node's name.
Interface to utility string handling.