SOL9 Sample: SAXXMLWriter

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * SAXXMLWriter.cpp 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2011/02/03

// Sample program to write an xml-data to a file stream by using SAXXMLWriter class.

#include <sol/COMInitializer.h>
#include <sol/Locale.h>

#include <sol/xml/SAXXMLWriter.h>


void _tmain(int argc, TCHAR** argv)
{
    if (argc !=2) {
        printf("Usage:%s output.xml\n", argv[0]);
        return;
    }
        
    COMInitializer comInitializer;
    Locale locale;
    try {

        SAXXMLWriter 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("root");

        SAXXMLAttributes attrs1;
        attrs1.addAttribute("name", "Foo");
        attrs1.addAttribute("email", "foo@foo.com");
        attrs1.addAttribute("department", "ipad");

        writer.startElement("developer", attrs1);
        writer.characters("This is a foo developer.");
        writer.endElement("developer");

        SAXXMLAttributes attrs2;
        attrs2.addAttribute("name", "Someone");
        attrs2.addAttribute("email", "someone@foo.com");
        attrs2.addAttribute("department", "android");

        writer.startElement("developer", attrs2);
        writer.characters("This is a someone developer.");
        writer.endElement("developer");

        writer.endElement("root");

        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: 25 Feb 2011

Copyright (c) 2011 Antillia.com ALL RIGHTS RESERVED.