Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6911051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:54:06+00:00 2026-05-27T08:54:06+00:00

I trying to write a xsd validator utility using MSXML 6.0. All is fine

  • 0

I trying to write a xsd validator utility using MSXML 6.0. All is fine and nice except this one line :

this->myReader->putProperty(L"schemas", pXS);

This throws this error : error C2664: 'ISAXXMLReader::putProperty' : cannot convert parameter 2 from 'MSXML2::IXMLDOMSchemaCollectionPtr' to 'VARIANT'

which is understandable but how can one add a schema instance to a reader?

FYI myReader is this :

ISAXXMLReader * myReader;

and initialized like this :

HRESULT hr = CoCreateInstance( __uuidof(SAXXMLReader60), 
                               NULL, 
                               CLSCTX_ALL,
                               __uuidof(ISAXXMLReader),
                               (void **)&this->myReader);

And pXS is :

MSXML2::IXMLDOMSchemaCollectionPtr   pXS;

pXS.CreateInstance(__uuidof(MSXML2::XMLSchemaCache60), NULL, CLSCTX_INPROC_SERVER);

Some of the links I read :

http://msdn.microsoft.com/en-us/library/ms762787(v=VS.85).aspx

http://support.microsoft.com/kb/309535

http://msdn.microsoft.com/en-us/library/windows/desktop/cc507429(v=VS.85).aspx

As usual MSDN documentation is really nice..

The example they provide works, but I need to collect all errors, so I translated the vb example in one of the links to C++. The only error which remains is this. Any help is appreciated.

Edit:

After following this nice link:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms766451(v=vs.85).aspx

C++ section :

The namespace to associate with the specified schema.
The empty string, “”, will associate the schema with the empty namespace, xmlns=””.

And doing this:

nResult = pIXMLDOMSchemaCollection2Ptr->add(_T(""), _T("c:\\temp\\collection.xsd"));

A nice crash happens. Does anyone know how on earth to add a schema without namespace in this thing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:54:07+00:00Added an answer on May 27, 2026 at 8:54 am

    OK after searching through I found the solution to my problem:

                MSXML2::IXMLDOMSchemaCollectionPtr pSchemaCache;
                pSchemaCache.CreateInstance(__uuidof(XMLSchemaCache60));
    
                if(FAILED(pSchemaCache.CreateInstance(__uuidof(XMLSchemaCache60))))
                {
                    throw AX::Base::Exception(__FILE__, __FUNCTION__, __LINE__, AX::Base::Exception::ABORT_EXECUTION, "Could not create Schema cache instance!");
                }
    
                if(FAILED(pSchemaCache->add(L"urn:books", myXSDFile.c_str())))
                {
                    throw AX::Base::Exception(__FILE__, __FUNCTION__, __LINE__, AX::Base::Exception::INVALID_PARAM_ERROR, "Could not add schema %s to Schema cache instance!", this->myXSDFile.c_str());
                }
                this->myReader->putProperty(L"schemas", _variant_t(pSchemaCache.GetInterfacePtr()));
    

    Hopefully someone else will benefit from this.

    Edit:

    How to add an empty namespace:

        bool const XmlValidator::validate()
        {
            //clear any previous validation errors
            this->myErrorHandler->clearErrorsAndWarnings();
            //do validation
            const std::wstring ns = this->converStringToWString(this->myXMLNamespace);
            try
            {
                // Check for existing schema associated with this namespace URI.
                ISchema* pExistingSchema = NULL;
                _bstr_t bstrNamespace = ns.c_str();
                HRESULT hr = this->mySchemaCache->getSchema(bstrNamespace, &pExistingSchema);
                if ( SUCCEEDED(hr) )
                {
                    // Remove the existing schema.
                    hr = this->mySchemaCache->remove(bstrNamespace);
                    if ( FAILED(hr) )
                        return false;
                }
                // Add the new schema.
                hr = this->mySchemaCache->add(bstrNamespace, _variant_t(this->converStringToWString(this->myXSDFile).c_str()));
                if ( FAILED(hr) )
                    return false;
            }
            catch(...)
            {
                throw AX::Base::Exception(__FILE__, __FUNCTION__, __LINE__, AX::Base::Exception::INVALID_PARAM_ERROR, "Xml namespace %s is different from Xsd namespace!", this->myXMLNamespace.c_str());
            }
    
            this->myReader->parseURL(this->converStringToWString(this->myXMLFile).c_str());
            //return true if there were no validation errors at all
            return this->myErrorHandler->getMyErrorsAndWarnings().size() == 0;  
        }
    

    Pay attention to this line : _bstr_t bstrNamespace = ns.c_str();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a GLOBAL CBT HOOK, this is My code, but my hooking
Trying to write Unit test for Silverlight 4.0 using Moq 4.0.10531.7 public delegate void
I am trying to create an XSD file in Eclipse using the text editor
Trying to write a trivial application, But I have stuck into one of the
I'm trying to write PHP to call a web service. Using SoapUI, I construct
I'm trying to write a schema for some XML documents using RELAX-NG, and when
I'm trying write a Ruby script that checks if user credentials are valid using
I'm trying to write my first xsd schema, and have run into an issue.
I' trying to write an xml file from Excel VBA using Microsoft XML 6.0.
In trying to write more testable Java code, I have been using the Model-View-Presenter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.