Skip to content

Files

Latest commit

f63dc70 · May 12, 2018

History

History
43 lines (36 loc) · 892 Bytes

README.md

File metadata and controls

43 lines (36 loc) · 892 Bytes

chtml

Small parser for html/xhtml in C.

Include a header

#include <chtml.h>

Initializing root element

chtml_element* root;
int return_value = chtml_parser_parse_file("test.html", &root);
if(return_value) {
	//... error while parsing
} else {
	// DOM is created
}
chtml_element_delete(&root); // removes the given element

Element properties

// example code for outputing root element name, content and first attribute key and value
#include <chtml.h>

int main(int argc, char** argv) 
{
	chtml_element* root;
	if(argc > 1) {
		if(!chtml_parser_parse_file(argv[1], &root)) {
			printf("Root element: \n");
			printf("\t name -> %s\n", root->tag);
			printf("\t content -> %s\n", root->content);
			printf("\t first attribute -> %s::'%s'\n", root->attributes[0]->key, root->attributes[0]->value);
		}
	}
	chtml_element_delete(&root);
	return 0;
}