SOL9 Sample: XMLDOMDocument

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * XMLDOMDocument.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2011/01/27

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

// Run as XMLDocument.exe SearchBox.xaml

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

#include <sol/xml/XMLDOMDocument.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;
  }
    
  COMInitializer comInitializer;
  Locale locale;

  try {
    
    XMLDOMDocument xmlDocument;

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

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

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

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

    XMLDOMDocument xmlDoc;
    _tprintf(_T("4 Try to loadXML the above xml string to an XMLDocument\n"));
    xmlDoc.loadXML(xml);  //load->loadXML
    _tprintf(_T("5 OK loaded the xml string\n"));

    xmlDoc.save(savedFileName);
    _tprintf(_T("6 Saved the xml string to a new file \"%s\"\n"), savedFileName);

  } catch (HRESULT hr) {
    _tprintf(_T("Exception 0x%x\n"), hr);
  } catch (Exception& ex) {
    ex.printf();
  } catch (XMLDOMParseError& err) {
    err.display();
  } 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.