SOL9 2.0 Sample: XMLDocument

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * XMLDocument.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/04/23

// Sample program to use open, load, save methods of XMLDocument class.

// Run as XMLDocument.exe SearchBox.xaml

#include <sol/COMInitializer.h>
#include <sol/xml/XMLDocument.h>


void _tmain(int argc, TCHAR** argv)
{
    if (argc !=2) {
        _tprintf(_T("Usage:\n%s sample.xml\n"), argv[0]);
        return;
    }

    if (GetFileAttributes(argv[1]) == 0xffffffff) {
        _tprintf(_T("File not found %s\n"), argv[1]);
        return;
    }

    try {
        COMInitializer comInitializer;

        {
            SOL::XMLDocument xmlDocument;

            _tprintf(_T("1 Try to open and read a xml file %s\n"), argv[1]);

            if (xmlDocument.open(argv[1])) {
                _tprintf(_T("2 OK. opend and read a file %s\n"), argv[1]);
                _bstr_t xml = "";
                xmlDocument.getXML(xml);

                _tprintf(_T("3 OK got a xml string:\n%s\n"), (const TCHAR*)xml);
                TCHAR savedFileName[MAX_PATH];

                _stprintf(savedFileName, _T("saved.%s"), argv[1]); 
                

                SOL::XMLDocument xmlDoc;
                _tprintf(_T("4 Try to load the above xml string to XMLDocument\n"));
                if (xmlDoc.load(xml)) {
                    _tprintf(_T("5 OK loaded the xml string\n"));

                    if (xmlDoc.save(savedFileName)) {
                        _tprintf(_T("6 Saved the xml string to a new file \"%s\"\n"), savedFileName);
                    } else {
                        _tprintf(_T("7 Failed to save a new file \"%s\"\n"), savedFileName);
                    }
                } else {
                    _tprintf(_T("8 Failed to load xml string\n"));
                }
            } else {
                _tprintf(_T("9 Failed to open a file %s\n"), argv[1]);
            } 
        }

    } catch (HRESULT hr) {
        _tprintf(_T("Exception %x\n"), hr);
    } catch (...) {
        _tprintf(_T("Exception %x\n"), GetLastError());
    }

}

Last modified: 11 Nov 2009

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