void callback_node_insert(myhtml_tree_t* tree, myhtml_tree_node_t* node, void* ctx)
{
    const char *tag_name = myhtml_tag_name_by_id(tree, myhtml_node_tag_id(node), NULL);
    const char *tag_name_parent = myhtml_tag_name_by_id(tree, myhtml_node_tag_id( myhtml_node_parent(node) ), NULL);
    
    printf("Insert %s to parent %s\n", tag_name, tag_name_parent);
}
void callback_node_remove(myhtml_tree_t* tree, myhtml_tree_node_t* node, void* ctx)
{
    const char *tag_name = myhtml_tag_name_by_id(tree, myhtml_node_tag_id(node), NULL);
    const char *tag_name_parent = myhtml_tag_name_by_id(tree, myhtml_node_tag_id( myhtml_node_parent(node) ), NULL);
    
    printf("Remove %s from parent %s\n", tag_name, tag_name_parent);
}
Esempio n. 3
0
void CMyHtmlParser::callbackNodeInserted(myhtml_tree_t* /*tree*/, myhtml_tree_node_t* node)
{
	HtmlTag tag;
	tag.type = myhtml_node_tag_id(node);
	const char* text = myhtml_node_text(node, nullptr);
	if (text)
		tag.text = QString::fromUtf8(text);

	for (myhtml_tree_attr_t *attr = myhtml_node_attribute_first(node); attr != nullptr; attr = myhtml_attribute_next(attr))
	{
		HtmlTagAttribute attribute;

		const char *name = myhtml_attribute_key(attr, nullptr);
		if (name)
			attribute.name = QString::fromUtf8(name);

		const char *value = myhtml_attribute_value(attr, nullptr);
		if (value)
			attribute.value = QString::fromUtf8(value);

		assert(name || value);
		tag.attributes.push_back(attribute);
	}

	_tags.push_back(tag);
}