Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on xml schema validation project. When I used MSXML6.dll API's in standalone project,it works fine.But when I used same API 0f MSXML2.dll API, it returns error code E-FAIL without any reason.
So, for that when I debug application, I noticed that there are some raw functions are executed behind every API and it returns error code.
I have copied code below and commented failed API.If someone had gone with this problem,please let me know.
Thanks

C++
bool cXML::validatefile(const char* fileName)
{
  MSXML2::IXMLDOMDocument2Ptr          pXMLDoc = NULL;
  MSXML2::IXMLDOMDocument2Ptr          pXSDDoc = NULL;
  MSXML2::IXMLDOMSchemaCollectionPtr   pSCache = NULL;
  MSXML2::IXMLDOMNodePtr       pNode = NULL;
  MSXML2::IXMLDOMNodeListPtr   pNodelist = NULL;
  MSXML2::IXMLDOMParseErrorPtr pError = NULL;
  HRESULT                      hr;
  long                         i = 0;
  long                         x = 0;

  CoInitialize(NULL);
  try{
    // Load validateNode.xml into a DOM instance.
    hr = pXMLDoc.CreateInstance("msxml2.domdocument");
    if (FAILED(hr)) {
      MessageBox(NULL, "Cannot create DOMDocument30 xml",
        "CreateInstance", MB_OK);
      return 0;
    }
    pXMLDoc->async = VARIANT_FALSE;
    pXMLDoc->validateOnParse = VARIANT_TRUE;
    if (pXMLDoc->load("pain00100103.xml") != VARIANT_TRUE)
    {
      show_parse_error(_bstr_t("Can't load pain.001.001.03.xml\n"),
        pXMLDoc->parseError);
      return 0;
    }

    // Load validateNode.xsd into a DOM instance.
    hr = pXSDDoc.CreateInstance("msxml2.domdocument");
    if (FAILED(hr)) {
      MessageBox(NULL, "Cannot create DOMDocument60 for xsd",
        "CreateInstance", MB_OK);
      return 0;
    }
    pXSDDoc->async = VARIANT_FALSE;
    pXSDDoc->validateOnParse = VARIANT_FALSE;
    if (pXSDDoc->load("pain.001.001.03.xsd") != VARIANT_TRUE)
    {
      show_parse_error(_bstr_t("Can't load pain.001.001.03.xsd\n"),
        pXSDDoc->parseError);
      return 0;
    }

    // Create a schema cache.
    hr = pSCache.CreateInstance(__uuidof(MSXML2::XMLSchemaCache60));
    if (FAILED(hr)) {
      MessageBox(NULL, "Cannot create XMLSchemaCache60",
        "CreateInstance", MB_OK);
      return 0;
    }

    // Point the XML doc's schema to the loaded schema cache.
    pXMLDoc->schemas = pSCache.GetInterfacePtr();

    //Below statement 'pSCache->add()' first parameter return error code E-FAIL
    hr = pSCache->add(L"urn:iso:std:iso:20022:tech:xsd:pain.001.001.03", pXSDDoc.GetInterfacePtr());
    if (FAILED(hr)) {
      MessageBox(NULL, "Cannot add schema", "add", MB_OK);
      return 0;
    }


What I have tried:

I tried to use MSXML6.dll but my applications other modules are dependent on MSXM2.dll, so I should have to continue with it.
Posted
Updated 25-Jul-17 21:09pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900