Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Schema Validation !!!

From: "ÀüÇüÁø" <hochiminh@----.--->
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;
 }
-----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------- 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent