Can't add a schema to a schema collection

51 Views Asked by At

Introduction:

I am not an expert of C++ nor of MSXML, this is why I am trying to start with things as simple as possible, such as taking some sample code of documentation and try modify some parameters.

Here's the thing, I am using this example to validate some XML files against XSD schemas. The code is running good on my computer, and it does what it is supposed to do as long as I keep the code exactly the same.

So I'd like to modify this code a little bit just so I can validate my own XML files against my own XSD schemas.

What is working :

So this code works perfectly with these files. This, at least, proves that I have no problem with my environment or my libraries.

What I changed :

As soon as I modify the code to make it validate my own files, it doesn't work anymore. Here are the few lines I changed :

This : CHK_HR(VariantFromString(L"books.xml", varXMLFileName));

Became this : CHK_HR(VariantFromString(L"facturx.xml", varXMLFileName));

This : CHK_HR(VariantFromString(L"books.xsd", varXSDFileName));

Became this : CHK_HR(VariantFromString(L"cii.xsd", varXSDFileName));

This : bstr = SysAllocString(L"urn:books");

Became this : bstr = SysAllocString(L"urn:un:unece:uncefact:data:crossindustry:3:draft");

Nothing too much spectacular, I am just changing files input. Also, my files should be pretty clean :

  • cii.xsd is the - I think - official CII XSD schemas, I found it there.
  • facturx.xml is an example file that should be CII compliant, I found it there

What is not working :

So, from now, with these modified lines, the code is stopping at this line :

CHK_HR(pSCache->add(bstr, varXSDObject));

When the program runs this line, it stops. Of course, this never occured while I was using the example files.

What I tried :

I tried to look at my input files to see if they could have obvious errors that would make the code crash, but I can't find any problem. I also tried with some other files and it still doesn't work.

I tried to put a try/catch(...) block around this line to see what would be the error, but it's not even triggering the catch block, the programs just crashes with no error or no stack trace.

I tried to look at the documentation or other posts in stackoverflow but I can't find anything relevant.

EDIT : I managed to print the error message by changing the macro from this :

// Macro that calls a COM method returning HRESULT value.
#define CHK_HR(stmt) do { hr=(stmt); if (FAILED(hr)) goto CleanUp; } while(0)

To this :

// Macro that calls a COM method returning HRESULT value.
#define CHK_HR(stmt) do { hr=(stmt); if (FAILED(hr)) {std::string message = std::system_category().message(hr);std::cout << message; goto CleanUp;} } while(0)

And the error message is : Unspecified error

How am I supposed to know what is the problem...

What am I asking :

So, I have a few question, if I can have one answer, it would help a lot :

What can I try to identify where the problem comes from? As I said I am not an expert of C++ so I don't really know the best ways to debug. Variables content are incomprehensible and I can't make it raise an exception or a stacktrace.

Is the problem coming from my code or from my files?

What is the problem?

I'm a little bit desesperate because this shouldn't be so hard to just take sample code and modify it, but it looks like it's harder than expected.

0

There are 0 best solutions below