Discussion:
MSXML & Validating
(too old to reply)
SAEED
2008-08-15 01:58:01 UTC
Permalink
am tryingto vlidate an schema under ver 6.0 but the validate() is
gone.

How do you validate an XML using an existing XSD?
BOOL ValidateXML(CString strFileName)
{
try
{
VARIANT xmlsource;
VARIANT xsdsource;
MSXML2::IXMLDOMDocumentPtr m_pDOMDoc;
MSXML2::IXMLDOMDocumentPtr pSchema;
IXMLDOMSchemaCollectionPtr pSchemaCache;
MSXML2::IXMLDOMParseErrorPtr pError;
HRESULT hr = m_pDOMDoc->put_async(VARIANT_FALSE);
VARIANT_BOOL fSuccess;
hr = m_pDOMDoc->load(xmlsource, &fSuccess);
if ( FAILED(hr) || fSuccess != VARIANT_TRUE)
{
AfxMessageBox("Loading the XML failed");
return false;
}


pSchema.CreateInstance(__uuidof(DOMDocument40));
pSchemaCache.CreateInstance(__uuidof(XMLSchemaCache40));
pSchema->put_async (VARIANT_FALSE);
if (!pSchema->load(xsdsource,&fSuccess) )
{
AfxMessageBox("Loading the XML Schema failed");
return FALSE;
}

m_pDOMDoc->schemas = pSchemaCache.GetInterfacePtr();
// pSchemaCache->add("urn:mynamespace", pSchema.GetInterfacePtr());


pError = m_pDOMDoc->validate();

???????????????????????????????????


// if (pError->errorCode != S_OK)
// {
//
// CString strError;
// strError.Format("Validation error: %d\n", pError->errorCode);
// strError += ((BSTR)pError->srcText);
// strError += "\nReason:";
// strError += ((BSTR)pError->reason);
// AfxMessageBox(strError);
// return FALSE;
// }
}

catch(...)
{
return FALSE;
}
return TRUE;
}
Martin Honnen
2008-08-15 12:24:17 UTC
Permalink
Post by SAEED
am tryingto vlidate an schema under ver 6.0 but the validate() is
gone.
pSchema.CreateInstance(__uuidof(DOMDocument40));
You need to use MSXML 6.0 and not 4.0 if you want to use the validate
method so try to use DOMDocument60 and XMLSchemaCache60.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Loading...