Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Libtidy HTML转换为XHTML并保存为字符串C_C_Htmltidy - Fatal编程技术网

将Libtidy HTML转换为XHTML并保存为字符串C

将Libtidy HTML转换为XHTML并保存为字符串C,c,htmltidy,C,Htmltidy,我使用此函数将put中的html转换为xhtml: char* cleanhtml(char* localhtml) { char *buffer_; static char *cleansed_buffer; // uses Libtidy to convert the buffer to XML TidyBuffer output = {0}; TidyBuffer errbuf = {0}; int rc = -1; bool ok; TidyDoc tdoc; tdoc = tid

我使用此函数将put中的html转换为xhtml:

char* cleanhtml(char* localhtml)
{
char *buffer_;
static char *cleansed_buffer;


// uses Libtidy to convert the buffer to XML
TidyBuffer output = {0};
TidyBuffer errbuf = {0};
int rc = -1;
bool ok;

TidyDoc tdoc;
tdoc = tidyCreate();                     // Initialize "document"

ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
    rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
    rc = tidyParseString(tdoc, localhtml);           // Parse the input
    rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
    rc = tidyRunDiagnostics( tdoc );               // Kvetch// If error, force output.
    rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
    rc = tidySaveBuffer( tdoc, &output );          // Pretty Print
    cleansed_buffer = (char*) malloc(output.size + 1);
    memcpy (cleansed_buffer, (char*)output.bp,output.size);
    tidyBufFree( &output );
    tidyBufFree( &errbuf );
    tidyRelease( tdoc );
    return cleansed_buffer;
}
但问题是它不能正常工作……由于某种原因,给出的xhtml无法解析,格式错误。那么,如何使用libtidy将给定的字符串转换为正确格式的xhtml呢

谁能给我一个链接到最新的libtidy DLL,包括C。我在任何地方都找不到它…甚至在那里的网站上也找不到

int TIDY_CALL tidySaveString(TidyDoc tdoc,tmbstr buffer, uint * buflen)
您可以简单地使用此函数将整洁的输出保存为字符串