Changeset 134 for Xml/Validator
- Timestamp:
- 01/10/08 15:31:25 (11 months ago)
- Files:
-
- 1 modified
-
Xml/Validator/WebApp/validator/OmeValidator.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Xml/Validator/WebApp/validator/OmeValidator.py
r130 r134 144 144 145 145 """ 146 The file the schema for the namespace has been loaded from 147 """ 148 theSchemaFile = None 149 """ 146 150 Create the message lists for this instance of the report object 147 151 """ … … 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()) … … 265 272 self.isXsdValid = False 266 273 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 274 275 def checkOldSchemas(self, inDocument): 276 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"]]: 277 # skip current one 278 if not thePossibleSchema[0] == self.theSchemaFile: 279 # load each old schema 280 try: 281 schema = etree.XMLSchema(etree.parse(schemaFilePath(thePossibleSchema[0]))) 282 except: 283 # chosen schema failed to laod 284 self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 285 # try validation 286 try: 287 schema.validate(inDocument) 288 err = schema.error_log.last_error 289 if not err: 290 # if valid then add info message "also valid under..." 291 self.warningList.append(ParseMessage(None, None, None, "Info", None, "File also valid under schema: " + thePossibleSchema[1])) 292 except etree.XMLSchemaValidateError: 293 err = False 268 294 269 295 def loadChoosenSchema(self): 270 296 # choose the schema source 271 297 # assume the new schema 272 theSchemaFile = "ome-2007-07-V2.xsd"298 self.theSchemaFile = "ome-2007-07-V2.xsd" 273 299 # if old schema 274 300 if self.theNamespace == "http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd": … … 276 302 if self.isOmeTiff: 277 303 # use special tiff version of old schema 278 theSchemaFile = "ome-fc-tiff.xsd"304 self.theSchemaFile = "ome-fc-tiff.xsd" 279 305 else: 280 306 # use normal version of old schema 281 theSchemaFile = "ome-fc.xsd"307 self.theSchemaFile = "ome-fc.xsd" 282 308 283 309 # loading the OME schema to validate against 284 310 try: 285 schema = etree.XMLSchema(etree.parse(schemaFilePath( theSchemaFile)))311 schema = etree.XMLSchema(etree.parse(schemaFilePath(self.theSchemaFile))) 286 312 except: 287 # chosen scema failed to laod313 # chosen schema failed to laod 288 314 self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 289 315 schema = None; 316 290 317 return schema 291 318
