We're Hiring!

help on loci.formats.tools.XMLValidate

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

help on loci.formats.tools.XMLValidate

Postby Kouichi_C_Nakamura » Thu Nov 15, 2018 2:35 pm

Now I'm using command line tools to review and edit OME-XML. But more often form within MATLAB using the `system` MATLAB function than directly from Command Prompt.

Then, although it's hard to say if this is really worthwhile, I thought why don't we have MATLAB function for OME-XML. The syntax is as follows:

Code: Select all
xml = bfTiffComment(imgfile)
xml = bfTiffComment(xmlfile)
[xml,res] = bfTiffComment(____,'Param',value)

% The pameters include 'OutXmlFile', 'NewXML', 'Indent', and 'XMLvalidation'.


This might be a good addition to Bio-Formats MATLAB toolbox (or not)?

So far I've managed to get `loci.formats.tools.TiffComment` and `loci.formats.tools.XMLIndent` working.

But I can't use `loci.formats.tools.XMLValidate`. Can I get your help, please?

Looking at the source code below,
https://github.com/ome/bio-formats-tool ... idate.java

the main usage appears to be `loci.formats.tools.XMLValidate.main(String[] args)`. So I prepared JavaArray of String args, which contains a file path for an XML file or OME.TIFF image file (i.e. args[0] = java.lang.String("raw.xml") or args[0] = java.lang.String("image01.ome.tif") ). But nothing happens.

I can validate the XML of the same files using the command line tool `xmlvalid`.
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: help on loci.formats.tools.XMLValidate

Postby mtbc » Fri Nov 16, 2018 11:18 am

Dear Kouichi,

Could you share some simple sample code somewhere so we can be sure that we properly understand what you're trying? It seems like you're calling XMLValidate.main with your ["raw.xml"] array? It could be that something is being printed, whether via standard output or Logback (which may first need configuring?), but in a way that isn't obvious from the caller's environment.

Cheers,
Mark
User avatar
mtbc
Team Member
 
Posts: 282
Joined: Tue Oct 23, 2012 10:59 am
Location: Dundee, Scotland

Re: help on loci.formats.tools.XMLValidate

Postby Kouichi_C_Nakamura » Fri Nov 16, 2018 12:12 pm

Dear Mark,

Thank you for asking.

The current version of the MATLAB function bfTiffComment is available below.
https://gist.github.com/kouichi-c-nakam ... 8cd1383c86

The syntax I'm now trying to implement is

Code: Select all
[xml, res] = bfTiffComment(imgfile,'XMLvalidation','on')


or

Code: Select all
[xml, res] = bfTiffComment(xmlfile,'XMLvalidation','on')


The relevant part of the MATLAB code is...
Code: Select all
y = javaArray('java.lang.String',1); % ... equivalent of `String[] y = new String[1];`
y(1) = java.lang.String(imgfile); % .... equilvalent to `y[0] = java.lang.String(imgfile);`
   
res = evalc('loci.formats.tools.XMLValidate.main(y)'); %TODO


`y`'s class is java.lang.String[]

imgfile in this case is 'file01.ome.tif' or 'file01.xml'.

Although I can't really get it work, because I don't know how to configure Eclipse to make loci.tools available, my imaginary Java code is as below:

Code: Select all
import java.lang.String;
import loci.formats.tools.XMLValidate;

public class K_ValidateXML {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      
      String[] s = new String[1];
      
      s[0] = new String("\\\\xxxxx\\xxxxx\\xxxxx.tif");
   
      XMLValidate(s);
      
   }
}




Does this clarify the matter?

Best,
Kouichi
Last edited by Kouichi_C_Nakamura on Mon Nov 19, 2018 3:30 pm, edited 1 time in total.
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: help on loci.formats.tools.XMLValidate

Postby jburel » Mon Nov 19, 2018 3:04 pm

Hi Kouichi

I have tried to follow what you want to achieve
i.e. specifying a file name either xml or ome.tiff
but when I run:
Code: Select all
[xml, res] = bfTiffComment('my_file.xml','XMLvalidation','on')


I cannot pass the input check step.
Is that the usage you are thinking of?

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: help on loci.formats.tools.XMLValidate

Postby Kouichi_C_Nakamura » Mon Nov 19, 2018 3:37 pm

Thank you for testing.

In my environment, it works but res is empty.

inputParser checks if imgfile really exists. Please note that if ''my_file.xml" is not a real file path, it won't run.

I've just updated the gist to make sure we're using the same code.
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: help on loci.formats.tools.XMLValidate

Postby jburel » Wed Nov 21, 2018 11:42 am

Hi Kouichi

The reason it was failing for me is due to the isfile function used to check the file
This was introduced in R2017b and I am currently running R2017a
I will upgrade to a more recent version of Matlab.
R2017b should be the minimum version we want to support.

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: help on loci.formats.tools.XMLValidate

Postby Dominik » Wed Nov 21, 2018 11:49 am

I just tested it with 2018b, and an example xml from https://downloads.openmicroscopy.org/im ... L/2016-06/ . No problem there:

Code: Select all
>> bfTiffComment('z-series-time-series.ome.xml','XMLvalidation','on')
ans =

    '<?xml version="1.0" encoding="UTF-8"?>
     <OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06
                              http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
       <Image ID="Image:0" Name="18x24y1z5t1c8b-text">
         <AcquisitionDate>2010-03-02T10:01:15</AcquisitionDate>
         <Pixels DimensionOrder="XYZCT" ID="Pixels:0:0" Type="uint8" SizeX="18" SizeY="24"
                     SizeZ="5" SizeC="1" SizeT="5">
           <Channel Color="-2147483648" ID="Channel:0"/>
...


Regards,
Dominik
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am

Re: help on loci.formats.tools.XMLValidate

Postby Kouichi_C_Nakamura » Wed Nov 21, 2018 1:49 pm

Thank you guys for testing it out.

To clarify the matter, my issue is `res` output of `bfTiffcomment` being empty even when 'XMLvalidation','on' was passed. The value of`res` should look like something similar to:

Code: Select all
[~/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]$


`evalc` doesn't seem to capture anything. I still can't get OMERO jar files working in Eclipse or from within ImageJ, so cannot test Java code directly...
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: help on loci.formats.tools.XMLValidate

Postby jburel » Thu Nov 22, 2018 12:05 pm

Hi Kouichi
I now have R2018b running, so I can pass the first hurdle
Unfortunately, the current status of the XMLValidate class will not allow you to achieve what you want.
The process method validates the file by delegating to another class
Code: Select all
XMLTools.validateXML(sb.toString(), label)

but the value returned by XMLTools.validateXML is never propagated so using the process method as it stands will not be useful.
The text printed out when using the CLI tools, is the output of the log file i.e.
Code: Select all
LOGGER.info("No validation errors found.");


The main method never returns anything (that cannot be changed), and it currently contains too much logic so it should not be used in your case.

One option for now is to rewrite the logic of XMLValidate in your Matlab function.
We are currently working on Bio-Formats version 6, and we can fix that class in that version. So if you are willing, you could try it out when we have it in place. We produce internal milestone so you could "test" before the official release.

Sorry for not having an easier option to offer at this point.

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: help on loci.formats.tools.XMLValidate

Postby Kouichi_C_Nakamura » Tue Nov 27, 2018 2:55 pm

Thank you, Jmarie.

The code below works in MATLAB and returns 1 (valid) or 0 (invalid).
Code: Select all
res = loci.common.xml.XMLTools.validateXML(xml, "XML");


But I don't think I can retrieve the meaningful output from LOGGER object.

I can't really read shell script well, but I wonder why we can see the output in case of command line tools but not in case of direct use of XMLvalidate, even though they depend on the same Java class. I thought I should be able to translate the command line tool into MATLAB.

Best,
Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Next

Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest