Changeset 131 for Xml/Validator/Backend/OmeValidator.py
- Timestamp:
- 01/10/08 15:11:22 (10 months ago)
- Files:
-
- 1 modified
-
Xml/Validator/Backend/OmeValidator.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Xml/Validator/Backend/OmeValidator.py
r129 r131 143 143 thePrefix = None 144 144 145 """ 146 The file the schema for the namespace has been loaded from 147 """ 148 theSchemaFile = None 145 149 """ 146 150 Create the message lists for this instance of the report object … … 241 245 # loading the OME schema to validate against 242 246 schema = self.loadChoosenSchema() 247 if schema is None: 248 return 249 243 250 # create an IO string for the xml string provided 244 251 stringXml = StringIO(self.theDom.toxml()) … … 262 269 self.isXsdValid = False 263 270 self.errorList.append(ParseMessage(None, err.line, None, "XSD", None, err.message)) 271 if self.isXsdValid: 272 self.checkOldSchemas(document) 264 273 except etree.XMLSchemaValidateError: 265 274 self.isXsdValid = False 266 275 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 268 296 269 297 def loadChoosenSchema(self): 270 298 # choose the schema source 271 299 # assume the new schema 272 theSchemaFile = "ome-2007-07-V2.xsd"300 self.theSchemaFile = "ome-2007-07-V2.xsd" 273 301 # if old schema 274 302 if self.theNamespace == "http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd": … … 276 304 if self.isOmeTiff: 277 305 # use special tiff version of old schema 278 theSchemaFile = "ome-fc-tiff.xsd"306 self.theSchemaFile = "ome-fc-tiff.xsd" 279 307 else: 280 308 # use normal version of old schema 281 theSchemaFile = "ome-fc.xsd"309 self.theSchemaFile = "ome-fc.xsd" 282 310 283 311 # loading the OME schema to validate against 284 312 try: 285 schema = etree.XMLSchema(etree.parse(schemaFilePath( theSchemaFile)))313 schema = etree.XMLSchema(etree.parse(schemaFilePath(self.theSchemaFile))) 286 314 except: 287 # chosen scema failed to laod315 # chosen schema failed to laod 288 316 self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 289 317 schema = None; 318 290 319 return schema 291 320
