Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Schema Validation !!! Schema Validation !!!To: NULL Date: 5/2/2006 11:25:00 AM
I'm working on development with MSXML4.0 SP2. in VS2003 C++.
What I want is to verify validity of a certain schema if it is properly
created according to XMLSchema 1.0 standard.
For instance,
-----------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name" type="xs:string"/>
<xs:element name="123address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
</xs:schema>
-----------------------------------------------------------------------------------------------------------
In these schema, in the name attribute of second element, you'll see it has
invalid value of "123address" for the name value.
I tried to examine these schema in MSXML 4.0 SP2 to prove invalidity of the
schema but failed.
Following codes are what i used.
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
MSXML2::IXMLDOMDocument2Ptr pXmlDoc;
pXmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
IVBMXNamespaceManagerPtr pNamespacenamanager;
pNamespacenamanager.CreateInstance(__uuidof(MSXML2::MXNamespaceManager40));
pXmlDoc->async = VARIANT_FALSE;
pXmlDoc->resolveExternals = VARIANT_FALSE;
pXmlDoc->validateOnParse = VARIANT_TRUE;
pXmlDoc->setProperty(_T("SelectionNamespaces"),
_T("xmlns:xs='http://www.w3.org/2001/XMLSchema'"));
if (FALSE != pXmlDoc->load(lpszPathName))
{
MSXML2::IXMLDOMDocument2Ptr pXsdDoc;
pXsdDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
pXsdDoc->async = VARIANT_FALSE;
pXsdDoc->resolveExternals = VARIANT_TRUE;
pXsdDoc->validateOnParse = VARIANT_TRUE;
//pXsdDoc->setProperty(_T("ProhibitDTD"), VARIANT_FALSE);
if (FALSE != pXsdDoc->load(_T("http://www.w3.org/2001/XMLSchema.xsd")))
{
MSXML2::IXMLDOMSchemaCollection2Ptr pSchemaCache;
HRESULT hr =
pSchemaCache.CreateInstance(__uuidof(MSXML2::XMLSchemaCache40));
pSchemaCache->validateOnLoad = VARIANT_FALSE;
pSchemaCache->add(_T("http://www.w3.org/2001/XMLSchema"),
pXsdDoc.GetInterfacePtr());
//pSchemaCache->add(_T("http://www.w3.org/2001/XMLSchema"),
_T("http://www.w3.org/2001/XMLSchema.xsd"));
pXmlDoc->schemas = pSchemaCache.GetInterfacePtr();
MSXML2::IXMLDOMParseErrorPtr pError = pXmlDoc->validate();
if (S_OK != pError->errorCode)
{
CString strReason(pError->reason.GetBSTR());
}
}
else
{
MSXML2::IXMLDOMParseErrorPtr pError = pXsdDoc->parseError;
CString strReason(pError->reason.GetBSTR());
long line = pError->line;
long linePos = pError->linepos;
}
}
else
{
MSXML2::IXMLDOMParseErrorPtr pError = pXmlDoc->parseError;
CString strReason(pError->reason.GetBSTR());
long line = pError->line;
long linePos = pError->linepos;
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
