- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to load and validate an XML file against an XML Schema, and since there doesn't seem to be any easy method for this in fortran, I'm just going to use some c++ code. I want to be able to run this on other machines with just the executable fortran, so I think I need a c++ dll linked into the fortran code. I've read various posts with pieces of code to call c++ dlls, but I can't put it all together. Can anyone tell me what changes I can make to my c++ code to make it a dll and export the files I need, then what fortran code to call it with to match the naming conventions? I'm also open to suggestions if there is a way to do this with just fortran, but so far I've only found parsers.
Thanks,
Chip
validxml.cpp
#include
#include
#import
using namespace std;
using namespace MSXML2;
void dump_com_error(_com_error &e);
// validate returns 1 for valid and -1 for invalid xml file
int validate(_bstr_t strFile)
{
int intResult = 0;
// Initialize objects and variables.
MSXML2::IXMLDOMDocument2Ptr pXMLDoc = NULL;
MSXML2::IXMLDOMParseErrorPtr pError = NULL;
_bstr_t strResult = "";
// Create a DOMDocument and set its properties.
HRESULT hr = pXMLDoc.CreateInstance(__uuidof(DOMDocument60));
pXMLDoc->async = VARIANT_FALSE;
pXMLDoc->validateOnParse = VARIANT_TRUE;
pXMLDoc->resolveExternals = VARIANT_TRUE;
// Load and validate the specified file into the DOM.
hr = pXMLDoc->load(strFile);
pError = pXMLDoc->parseError;
// Return validation results in message to the user.
if (pError->errorCode != S_OK) {
intResult = -1;
}
else {
intResult = 1;
}
// Clean up and destroy objects.
if (pXMLDoc) pXMLDoc.Release();
if (pError) pError.Release();
return intResult;
}
// returns -1 for wrong usage, 0 for all files valid,
// or the argument number of the first invalid file
int main(int argc, char* argv[])
{
if (argc > 1) {
CoInitialize(NULL);
try{
for (int i = 1; i < argc; i++) {
if (-1 == validate(argv)) {
//cout<<"error in file "<<return i;
}}}
catch(_com_error &e) {
dump_com_error(e);
}}
else {
//cout<<"Correct usage: validxml filename.xml [filename2.xml+] ";
return -1;
}
//cout<<"0 ";
return 0;
}
void dump_com_error(_com_error &e)
{
printf("Error ");
printf("a Code = %08lx ", e.Error());
printf("a Code meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("a Source = %s ", (LPCSTR) bstrSource);
printf("a Description = %s ", (LPCSTR) bstrDescription) ;
}
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page