What is the best way to generate HTML output in C ++?

Possible duplicate:
C ++ HTML template structure, template library, HTML generator library

I have a program that contains many tables, so I want to track them in the log files when I debug the program. I need color formatted output, so I thought I wrote it in HTML format. So what is the best way to create HTML files in C ++?

The trivial way is so disgusting and error prone:

std::stringstream ret; ret << "<TABLE BORDER=\"1\" CELLBORDER=\"0\">\n"; ret << " <TR>\n"; ... 

So, I thought I wrote an HTML wrapper, but I think there are so many for this reason.

I want a statically typed HTML wrapper in C ++ with this syntax or similar:

 CHtmlHtml Html; Html << Body() % Id("1") << H1("My First Heading") << << P("My first paragraph."); 

or in this case

 CHtmlTable table; table % Border(1) % CellBorder(0) << Tr() << Td("Text") % Colspan(4); 

Is there any similar project?

+6
source share
1 answer

HTML and XML use the same syntax, so you can simply use the C ++ XML library (like TinyXML) to dynamically create all the nodes you need.

This page shows how to use TinyXML to create XML documents (or, in your case, HTML).

You may have to play a little (for example, remove the XML declaration at the top of the generated file), but I think you can easily create a wrapper for it.

+3
source

Source: https://habr.com/ru/post/904863/


All Articles