Hi,
   
  Im developing a project using xerces. 
  I would like to use xerces for validating the DOM object created at run time 
(and not read from the file) agains xsd.
   
  I have a problem with setting DOMConfiguration that I retrieve from Document. 
I can set the validation flag to true, myErrorHandler but for some reason ?? I 
cannot set the "schema-type" and "schema-location". I get an error 
NOT_SUPPORTED_ERR, but I don't know why the feature cannot be set.
   
  I set the "validation" & ErrorHandler before I call set for "schema-type" and 
"schema-location". What could be the reason for this problem?
  How can I find out what is the problem - can I look at some Error object, 
that would be populated when the function set setParameter is called?
   
  If sb would have a piece of code that actually is doing the validation of DOm 
against xsd I would be grateful.
   
  Simplified code below
   
  thanks in advance
   
  Rafal
   
  static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS); 
  
   
      
DOMBuilder *parser = 
impl->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, NULL);
  parser->setFeature(XMLUni::fgDOMNamespaces, true);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
   
  parser->setFeature(XMLUni::fgDOMValidateIfSchema, true);
   
  parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);
DOMCountErrorHandler errorHandler;
parser->setErrorHandler(&errorHandler);
   
  doc = parser->parseURI(X("shiporder.xml"));
   
  DOMWriter         *theSerializer = 
((DOMImplementationLS*)impl)->createDOMWriter();
   
              DOMErrorHandler *myErrorHandler = new DOMPrintErrorHandler();
            theSerializer->setErrorHandler(myErrorHandler);
              // set feature if the serializer supports the feature/mode
            if 
(theSerializer->canSetFeature(XMLUni::fgDOMWRTSplitCdataSections, false))
                theSerializer->setFeature(XMLUni::fgDOMWRTSplitCdataSections, 
false);
              if 
(theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, false))
                
theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, false);
              if 
(theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false))
                theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, 
false);
              if (theSerializer->canSetFeature(XMLUni::fgDOMWRTBOM, false))
                theSerializer->setFeature(XMLUni::fgDOMWRTBOM, false);
              if (theSerializer->canSetFeature(XMLUni::fgDOMValidateIfSchema, 
true))
                theSerializer->setFeature(XMLUni::fgDOMValidateIfSchema, true);
   
          DOMString strSchemaType = "http://www.w3.org/2001/XMLSchema";;
        DOMString strSchemaLocation = "shiporder.xsd";
   
          if(config->canSetParameter(X("validate"), (void*)true))
                config->setParameter(X("validate"), (void*)true);
                
        if (config->canSetParameter(X("schema-type"),NULL))
                config->setParameter(X("schema-type"),NULL);
  
        if (config->canSetParameter(X("schema-type"),(void*)&strSchemaType))
                config->setParameter(X("schema-type"),(void*)&strSchemaType);
        
        if 
(config->canSetParameter(X("schema-location"),(void*)&strSchemaLocation))
                
config->setParameter(X("schema-location"),(void*)&strSchemaLocation);
                
              XMLFormatTarget *myFormTarget;
            if (goutputfile)
                myFormTarget = new LocalFileFormatTarget("test.xml");
            else
                myFormTarget = new StdOutFormatTarget();                
                
        doc->normalizeDocument();
   
          theSerializer->writeNode(myFormTarget, *doc);
   
  ...

 
---------------------------------
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.

Reply via email to