How do I validate a file on the command line?
First, download and install the Bio-Formats command line tools.
A full tutorial can be found here. In brief, you download and unzip the tools to produce a collection of command line scripts for Unix/Mac and batch files for Windows. The two commands we will use are xmlvalid and tiffcomment.
-
xmlvalid– a command-line XML validation tool -
tiffcomment– extracts the OME-XML block in an OME-TIFF file from the comment in the TIFF's first IFD entry.
All scripts require loci_tools.jar is downloaded to the same directory as the command line tools.
Then to validate an OME-XML file sample.ome use:
xmlvalid sample.ome
This validates the XML directly.
Then to validate an OME-TIFF file sample.ome.tif use:
tiffcomment sample.ome.tif | xmlvalid
This extracts the OME-XML from the TIFF then passed it to the validator.
Typical successful output is:
[~/Work/bftools]$ ./xmlvalid sample.ome
Parsing schema path
http://www.openmicroscopy.org/Schemas/OME/2010-06/ome.xsd
Validating sample.ome
No validation errors found.
[~/Work/bftools]$
If any errors are found they are reported. When correcting errors it is usually best to work from the top of the file as errors higher up can cause extra errors further down. In this example the output shows 3 errors but there are only 2 mistakes in the file.
[~/Work/bftools]$ ./xmlvalid broken.ome
Parsing schema path
http://www.openmicroscopy.org/Schemas/OME/2010-06/ome.xsd
Validating broken.ome
cvc-complex-type.4: Attribute 'SizeY' must appear on element 'Pixels'.
cvc-enumeration-valid: Value 'Non Zero' is not facet-valid with respect
to enumeration '[EvenOdd, NonZero]'. It must be a value from the enumeration.
cvc-attribute.3: The value 'Non Zero' of attribute 'FillRule' on element
'ROI:Shape' is not valid with respect to its type, 'null'.
Error validating document: 3 errors found
[~/Work/bftools]$

