SOL9 Sample: XMLDOMSchemaCollection
|
1 Screenshot
2 Source code
/*
* XMLDOMSchemaCollection.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2011/01/27
// Sample program to read and parse an xml file by using SAXXMReader class.
#include <sol/COMInitializer.h>
#include <sol/Locale.h>
//#include <sol/xml/SAXXMLReader.h>
//#include <sol/xml/XMLDOMSchemaCollection.h>
#include <sol/xml/XMLDOMDocument.h>
void _tmain(int argc, TCHAR** argv)
{
if (argc !=3) {
_tprintf(_T("Usage:\n%s mail.xsd mail.xml\n"), argv[0]);
_tprintf(_T("Causing Error:\n%s sample.xsd bad.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* xsdFile = argv[1]; //sample.xsd
const TCHAR* xmlFile = argv[2]; //sample.xml
XMLDOMDocument xmlDocument;
XMLDOMDocument xsdDocument;
xsdDocument.putAsync(VARIANT_FALSE);
xsdDocument.open(xsdFile);
_tprintf(_T("1 OK. Loaded %s to XMLDOMDocument\n"), xsdFile);
SOL::XMLDOMSchemaCollection schemaCollection;
_tprintf(_T("2 OK. XMLDOMSchemaCollection\n"));
//The first parameter of the following XMLDOMSchemaCollection::add method is merely
//a fixed sample targetNamespace "http://www.w3.org/2001/XMLSchema".
//If a targetNamespace in xsdFile is different from the above namespace value,
//then a mismatching error in targetNamespaces will occur.
schemaCollection.add("http://www.w3.org/2001/XMLSchema", _variant_t(xsdFile));
_tprintf(_T("3 OK. Added xsdFie(%s) to XMLDOMSchemaCollection \n"), xsdFile);
schemaCollection.putValidateOnLoad(VARIANT_TRUE);
schemaCollection.validate();
_tprintf(_T("4 OK. Validated XMLDOMSchemaCollection of xsdFile=%s\n"), xsdFile);
schemaCollection.display();
xmlDocument.putValidateOnParse(VARIANT_TRUE);
xmlDocument.putAsync(VARIANT_FALSE);
xmlDocument.putRefschemas(_variant_t((IUnknown*)schemaCollection ) );
_tprintf(_T("5 OK. Put RefSchema to XMLDOMDocument\n"));
xmlDocument.open(xmlFile);
_tprintf(_T("6 OK. Opend xmlFile=%s\n"), xmlFile);
xmlDocument.validate();
_tprintf(_T("7 OK. Validated xmlDocument\n"));
} 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 (XMLDOMParseError& ex) {
ex.display();
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.