I would like to know if is possible to check/capture the result of a "schemavalidate"/"xmlvalidate" operation?
The idea is to parse the files in a folder, try to validate each of them against an XSD and get the status of the operation in a property (eventually, output the status and the result of the operation in a log file).
The status of the validation can be then checked in order to know if some other tasks should be performed or not on that particular XML file.
For example:
<target name="convert-user-folder">
<echo>${user.folder}</echo>
<!-- Iterate all XML files in the folder -->
<foreach target="validate-xml-file" param="user.input.xml">
<path>
<fileset dir="${user.folder}">
<include name="*.xml" />
</fileset>
</path>
</foreach>
</target>
<target name="validate-xml-file">
<echo message="Validating ${user.input.xml}"/>
<!-- Checking if XML is well formed -->
<echo message="Checking if ${user.input.xml} is well formed"/>
<xmlvalidate file="${user.input.xml}" failonerror="false" lenient="true"/>
<!-- HOW WE COULD CHECK THE RESULT OF THE VALIDATION OPERATIONS
WITHOUT EXITING ?-->
<!-- Checking if file validates against XSD -->
<echo message="Checking if ${user.input.xml} validates against schema"/>
<schemavalidate noNamespaceFile="${xsds.dir}/userInput.xsd"
file="${user.input.xml}" failonerror="false"/>
<!-- HOW WE COULD CHECK THE RESULT OF THE VALIDATION OPERATIONS
WITHOUT EXITING? -->
<!-- HERE WE SHOULD GET IN A PROPERTY THE STATUS OF THE OPERATION AND WRITE
IN A FILE SOMETHING LIKE : "OPERATION STATUS: SUCCESS/FAILURE: The reason
was: something from the schemavalidate output" -->
<!-- IF THE OPERATION WAS SUCCESSFUL WE SHOULD CALL SOME TASKS OTHERWISE
CALL OTHER TASKS -->
</target>
Thanks in advance for your suggestions.
What I needed actually was the trycatch from antcontrib. This solved my problem as in the snippet below.
<target name="validate-xml-file">
<echo message="Validating ${user.input.xml}"/>
<!-- Checking if XML is well formed -->
<echo message="Checking if ${user.input.xml} is well formed"/>
<trycatch property="xml.well.formed.result">
<try>
<xmlvalidate file="${user.input.xml}" failonerror="true" lenient="true"/>
</try>
<catch/>
<finally/>
</trycatch>
<!-- Checking if file validates against XSD -->
<echo message="Checking if ${user.input.xml} validates against schema"/>
<trycatch property="schema.validation.result">
<try>
<schemavalidate noNamespaceFile="${xsds.dir}/userInput.xsd"
file="${user.input.xml}" failonerror="true"/>
</try>
<catch/>
<finally/>
</trycatch>
<!-- Create two properties for the results of the validation -->
<condition property="xml.well.formed.result.set" else="false">
<isset property="xml.well.formed.result"/>
</condition>
<condition property="schema.validation.result.set" else="false">
<isset property="schema.validation.result"/>
</condition>
<!-- Here we can write into a HTML format the result of the operation according
to the xml.well.formed.result, schema.validation.result a.s.o.) -->
<!-- Also, perform something according to the validation or not of the XML -->
<if>
<or>
<equals arg1="${xml.well.formed.result.set}" arg2="true"/>
<equals arg1="${schema.validation.result.set}" arg2="true"/>
</or>
<then>
<!-- Here we call some task -->
</then>
<else>
<!-- Here we call some other task or just fail to fw the failure -->
</else>
</if>