SAEED
2008-08-15 01:58:01 UTC
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;
}
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;
}