我想知道是否可以检查/捕获“schemavalidate”/“xmlvalidate”操作的结果?
这个想法是解析文件夹中的文件,尝试针对 XSD 验证每个文件并在属性中获取操作状态(最终,在日志文件中输出状态和操作结果)。
然后可以检查验证的状态,以了解是否应该对那个特定的 XML 文件执行一些其他任务。
例如:
<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>
提前感谢您的建议。