如何将 libtidy 与 tidyParseBuffer() 一起使用?

发布于 2024-08-08 09:52:14 字数 704 浏览 2 评论 0原文

我试图用 libtidy (C 语言)清理一些 HTML,问题是:

我想用 tidyParseBuffer() 构造一个 TidyDoc (树状结构)。

我对 tidyParseFile() 没有问题;关于 tidyParseBuffer():我确定我正确读取了文件,并且我提供给 tidyParseBuffer() 的 TidyBuffer 结构已正确填充。

有什么想法吗?

这是代码:

    //declaration
 tidyInput = malloc(sizeof(TidyBuffer));
 tidyOutput = malloc(sizeof(TidyBuffer));
 do { 
      len = fread(pbInputData, 1, nInputData, h->file);
      tidyBufAttach(tidyInput, (void*)pbInputData, len);
      tidyParseBuffer(h->doc, tidyInput);  // doc is the TidyDoc 
 } while (len >= nInputData);
 tidyOptSetBool(h->doc, TidyForceOutput, yes);

 tidySaveFile(handler->doc, "C://test.xhtml");

我确实简化了代码。

I'm trying to clean some HTML with libtidy (C language), the problem is:

I want to construct a TidyDoc (a tree-like structure) with tidyParseBuffer().

I have no problem with tidyParseFile(); about tidyParseBuffer(): I'm sure I read the file properly and that the TidyBuffer structure I give to tidyParseBuffer() is correctly filled.

Any ideas?

here is the code:

    //declaration
 tidyInput = malloc(sizeof(TidyBuffer));
 tidyOutput = malloc(sizeof(TidyBuffer));
 do { 
      len = fread(pbInputData, 1, nInputData, h->file);
      tidyBufAttach(tidyInput, (void*)pbInputData, len);
      tidyParseBuffer(h->doc, tidyInput);  // doc is the TidyDoc 
 } while (len >= nInputData);
 tidyOptSetBool(h->doc, TidyForceOutput, yes);

 tidySaveFile(handler->doc, "C://test.xhtml");

I did simplify the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2024-08-15 09:52:14

问题源于这样的事实:您尝试以块的形式解析文件的内容,将每个块读入缓冲区并为每个块调用 tidyParseBuffer()

tidyParseXxx() 函数通过在一次调用中解析整个输入来进行操作,因此要执行您想要的操作,您应该查看 TidyInputSourcetidyParseSource()

The problem stems from the fact that you are trying to parse the contents of a file in chunks, reading each chunk into a buffer and calling tidyParseBuffer() for each chunk.

The tidyParseXxx() functions operate by parsing the whole input in a single call, so to do what you want you should take a look at TidyInputSource and tidyParseSource().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文