SOL9 Sample: XMLDOMDocumentTransform

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL9
// 2011/02/06

// Sample program to tranform xml by xsl using XMLDOMNode::transformNodeToObject.

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


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

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

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

  COMInitializer comInitializer;
  Locale locale;
  
  try {
    const TCHAR* xslFile = argv[1];
    const TCHAR* xmlFile = argv[2];

    _tprintf(_T("1 Create XMLDOMDocument for xsl. \n"));
    SOL::XMLDOMDocument xslDocument;

    xslDocument.open(xslFile);
    _tprintf(_T("2 Opened a file %s\n"), xslFile);

    SOL::XMLDOMDocument xmlDocument;
    //2011/02/10 Added the following two lines,
    xmlDocument.putResolveExternals(VARIANT_TRUE);
    xmlDocument.setProperty("ProhibitDTD", VARIANT_FALSE);

    xmlDocument.open(xmlFile);
    _tprintf(_T("3 Opened a file %s\n"), xmlFile);

    SOL::XMLDOMDocument transformedDocument;    

    _tprintf(_T("4 Call XMLDOMNode::transformNodeToObject()\n"));
    xmlDocument.transformNodeToObject((MSXML2::IXMLDOMNode*)xslDocument, 
        _variant_t((IUnknown*)transformedDocument) );

    _bstr_t transformedXML = transformedDocument.getXML();
    _tprintf(_T("5 OK. Transformed XML=[\n%s]\n"), (const TCHAR*)transformedXML);

  } 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 comError(ex);
    comError.printf();
  }

}

Last modified: 2 May 2016

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