SOL9 Sample: SAXHTMLWriter
|
1 Screenshot
2 Source code
/*
* SAXHTMLWriter.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2011/02/15
// Sample program to write an html-data to a file stream by using SAXHTMLWriter class.
#include <sol/COMInitializer.h>
#include <sol/Locale.h>
#include <sol/xml/SAXHTMLWriter.h>
void _tmain(int argc, TCHAR** argv)
{
if (argc !=2) {
printf("Usage:%s output.html\n", argv[0]);
return;
}
COMInitializer comInitializer;
Locale locale;
try {
SAXHTMLWriter writer;
writer.putEncoding("utf-8");
writer.putStandalone(VARIANT_TRUE);
//Create a file stream specified by argv[1];
writer.create(argv[1]);
writer.startDocument();
writer.startElement("html");
writer.startElement("head");
writer.endElement("head");
writer.startElement("body");
writer.startElement("h1");
writer.characters("Hello world");
writer.endElement("h1");
writer.startElement("hr");
writer.endElement("hr");
SAXXMLAttributes attrs1;
attrs1.addAttribute("href", "http://www.antillia.com");
writer.startElement("a", attrs1);
writer.characters("This is a link to Antillia.com (http://www.antillia.com)");
writer.endElement("a");
writer.startElement("br");
writer.endElement("br");
writer.startElement("hr");
writer.endElement("hr");
SAXXMLAttributes attrs2;
attrs2.addAttribute("color", "red");
attrs2.addAttribute("size", "5");
writer.startElement("font", attrs2);
writer.characters("Goodbye world");
writer.endElement("font");
SAXXMLAttributes attrs3;
attrs3.addAttribute("src", "./ootabu_cat.jpg");
attrs3.addAttribute("align", "left");
writer.startElement("img", attrs3);
writer.endElement("img");
writer.startElement("body");
writer.endElement("html");
writer.endDocument();
} catch (HRESULT hr) {
_tprintf(_T("Exception 0x%x\n"), hr);
} catch (Exception& ex) {
ex.printf();
} catch (_com_error& ex) {
ComError error(ex);
error.printf();
} catch (...) {
_tprintf(_T("Exception %x\n"), GetLastError());
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.