3,055
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="GB2312"?>
<AllForms xmlns="http://KM-Soft.Company.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://KM-Soft.Company.com/namespace D:\Project\CAMDSExcelAddin\Config\CAMDSSchema.xsd">
<xs:schema xmlns="http://KM-Soft.Company.com/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://KM-Soft.Company.com/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
MSXML2::IXMLDOMDocument2Ptr pXMLDoc;
HRESULT hr = pXMLDoc.CreateInstance(/*"Msxml2.DOMDocument"*/__uuidof(MSXML2::DOMDocument40));
pXMLDoc->PutvalidateOnParse(VARIANT_TRUE);
pXMLDoc->async = VARIANT_FALSE;
//load the XSD file
MSXML2::IXMLDOMSchemaCollectionPtr pSchemaCache;
hr = pSchemaCache.CreateInstance(__uuidof(MSXML2::XMLSchemaCache40));
// pXSDDoc->async = VARIANT_FALSE;
hr = pSchemaCache->add("http://KM-Soft.Company.com/namespace","D:\\Project\\CAMDSExcelAddin\\Config\\CAMDSSchema.xsd");
pXMLDoc->schemas = pSchemaCache.GetInterfacePtr();
//call validate
hr = pXMLDoc->load("D:\\CAMDS.xml");
if(pXMLDoc->parseError->errorCode != S_OK)
{
_bstr_t parseError = _bstr_t(_T("Error code: "))+ _bstr_t(pXMLDoc->parseError->errorCode) +_bstr_t("\n") + _bstr_t("Reason: ")+ pXMLDoc->parseError->Getreason();
MessageBox(GetActiveWindow(), parseError, _T("Parse Error"),MB_OK);
return FALSE;
}