• Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 131 for Xml/Validator

Show
Ignore:
Timestamp:
01/10/08 15:11:22 (11 months ago)
Author:
andrew
Message:

Added check for validity against other versions of schemas

Files:
1 modified

  • Xml/Validator/Backend/OmeValidator.py (modified) (4 diffs)

Legend:

Unmodified
Added
Removed
  • Xml/Validator/Backend/OmeValidator.py

    r129 r131  
    143143        thePrefix = None 
    144144         
     145        """ 
     146        The file the schema for the namespace has been loaded from 
     147        """ 
     148        theSchemaFile = None 
    145149        """ 
    146150        Create the message lists for this instance of the report object 
    … …  
    241245                # loading the OME schema to validate against 
    242246                schema = self.loadChoosenSchema() 
     247                if schema is None: 
     248                        return 
     249                 
    243250                # create an IO string for the xml string provided 
    244251                stringXml = StringIO(self.theDom.toxml()) 
    … …  
    262269                                self.isXsdValid = False 
    263270                                self.errorList.append(ParseMessage(None, err.line, None, "XSD", None, err.message)) 
     271                        if self.isXsdValid: 
     272                                self.checkOldSchemas(document) 
    264273                except etree.XMLSchemaValidateError: 
    265274                        self.isXsdValid = False 
    266275                        self.errorList.append(ParseMessage(None, None, None, "XML", None, "Processing the XML data has generated an unspecified error in the XML sub-system. This is usually a result of an incorrect top level block. Please check the OME block is well-formed and that the schemaLocation is specified correctly. This may also be caused by a missing namespace prefix or incorrect xmlns attribute.")) 
    267                          
     276         
     277        def checkOldSchemas(self, inDocument): 
     278                for thePossibleSchema in [["ome-2007-07-V2.xsd","September 2007 V2"],["ome-2007-07-V1.xsd","June 2007 V1"],["ome-fc-tiff.xsd","2003 - Tiff Variant"], ["ome-fc.xsd","2003 - Standard version"]]: 
     279                        # skip current one 
     280                        if not thePossibleSchema[0] == self.theSchemaFile: 
     281                                # load each old schema 
     282                                try: 
     283                                        schema = etree.XMLSchema(etree.parse(schemaFilePath(thePossibleSchema[0]))) 
     284                                except: 
     285                                        # chosen schema failed to laod 
     286                                        self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 
     287                                # try validation 
     288                                try: 
     289                                        schema.validate(inDocument) 
     290                                        err = schema.error_log.last_error 
     291                                        if not err: 
     292                                                # if valid then add info message "also valid under..." 
     293                                                self.warningList.append(ParseMessage(None, None, None, "Info", None, "File also valid under schema: " + thePossibleSchema[1])) 
     294                                except etree.XMLSchemaValidateError: 
     295                                        err = False 
    268296         
    269297        def loadChoosenSchema(self): 
    270298                # choose the schema source 
    271299                # assume the new schema 
    272                 theSchemaFile = "ome-2007-07-V2.xsd" 
     300                self.theSchemaFile = "ome-2007-07-V2.xsd" 
    273301                # if old schema 
    274302                if self.theNamespace == "http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd": 
    … …  
    276304                        if self.isOmeTiff: 
    277305                                # use special tiff version of old schema 
    278                                 theSchemaFile = "ome-fc-tiff.xsd" 
     306                                self.theSchemaFile = "ome-fc-tiff.xsd" 
    279307                        else: 
    280308                                # use normal version of old schema 
    281                                 theSchemaFile = "ome-fc.xsd" 
     309                                self.theSchemaFile = "ome-fc.xsd" 
    282310                 
    283311                # loading the OME schema to validate against 
    284312                try: 
    285                         schema = etree.XMLSchema(etree.parse(schemaFilePath(theSchemaFile))) 
     313                        schema = etree.XMLSchema(etree.parse(schemaFilePath(self.theSchemaFile))) 
    286314                except: 
    287                         #chosen scema failed to laod 
     315                        # chosen schema failed to laod 
    288316                        self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 
    289                  
     317                        schema = None; 
     318                         
    290319                return schema 
    291320         

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/