当前位置: 首页 > news >正文

C HTML格式解析与生成

cmake报错替换 

if(NOT MyHTML_BUILD_WITHOUT_THREADS OR NOT MyCORE_BUILD_WITHOUT_THREADS)
    set(CMAKE_THREAD_PREFER_PTHREAD 1)
    if (WIN32)
        set(CMAKE_USE_WIN32_THREADS_INIT ON)
        set(CMAKE_THREAD_PREFER_PTHREADS TRUE)
        set(THREADS_PREFER_PTHREAD_FLAG TRUE)
    else ()
        find_package(Threads REQUIRED)
        if(NOT CMAKE_USE_PTHREADS_INIT)
            message(FATAL_ERROR "Could NOT find pthreads (missing: CMAKE_USE_PTHREADS_INIT)")
        endif()
    endif()
endif() 

测试

add_executable(example examples/myhtml/modify_and_serialize.c)
target_link_libraries(example ${PROJECT_LIB_STATIC})

代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <myhtml/serialization.h>/***  Write output*  @param  buffer*  @param  size*  @param  ptr*/
mystatus_t write_output(const char* data, size_t len, void* ctx)
{printf("%.*s", (int)len, data);return MyCORE_STATUS_OK;
}/***  Main procedure*  @return int*/
int main()
{// initalize html enginemyhtml_t *myhtml = myhtml_create();myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 1, 0);// init treemyhtml_tree_t *tree = myhtml_tree_create();myhtml_tree_init(tree, myhtml);// input stringconst char *input = "<html><head></head><body><a href=http://nu.nl></body></html>";// parse htmlmyhtml_parse(tree, MyENCODING_UTF_8, input, strlen(input));// collection of linksmyhtml_collection_t *collection = myhtml_get_nodes_by_name(tree, NULL, "a", 1, NULL);// iterate over all nodesfor (size_t i = 0; i < collection->length; ++i){// add attributemyhtml_attribute_add(collection->list[i], "title", 5, "my value", 8, MyENCODING_UTF_8);}// write the document againmyhtml_serialization_tree_callback(myhtml_tree_get_document(tree), write_output, NULL);myhtml_collection_destroy(collection);myhtml_tree_destroy(tree);myhtml_destroy(myhtml);// donereturn 0;
}
修改前

"<html><head></head><body><a href=http://nu.nl></body></html>

修改后

<html><head></head><body><a href="http://nu.nl" title="my value"></a></body></html>

参考

https://github.com/lexborisov/Modest

GitHub - lexborisov/myhtml: Fast C/C++ HTML 5 Parser. Using threads.


创作不易,小小的支持一下吧!


http://www.mrgr.cn/news/12555.html

相关文章:

  • 深度学习学习经验——深度学习名词字典
  • [Meachines] [Easy] jerry Tomcat用户暴力破解+war包webshell上传
  • 腾讯地图接入报错vue.runtime.esm.js:4605[Vue warn]: Error in v-on handler: “far <= 0“
  • 基于单片机的无线空气质量检测系统设计
  • SQL Server 查询语句中,对索引列做CONVERT的影响
  • STM32自制手持小风扇实验
  • HTTP/1和HTTP/2
  • 【C++】异常 详解
  • 解决ONENOTE复制文字到外部为图片(Ditto)
  • PyTorch构建神经网络
  • leetcode94:二叉树的中序遍历
  • 【pytorch深度学习——小样本学习策略】网格搜索和遗传算法混合优化支持向量机的小样本学习策略进行预测
  • Python的变量、关键字、命名规则、基本数据类型及类型转换
  • [每日一练]从表中创建DataFrame
  • PHP MySQL 插入多条数据
  • 【Google Maps JavaScript API】Right-to-Left Languages 实现指南
  • 10款免费电脑录屏软件盘点,2024年最新录屏工具排行榜
  • 23种设计模式详解-创建模式篇
  • 功能测试理论
  • Linux小项目 迷你服务端实现在线商城