Linux command line tool validating XSD 1.1?

梦想的初衷 提交于 2020-01-15 07:09:33

问题


Is there any command line tool that validates XML against a XSD version 1.1?

Xmllint does not validate version 1.1.


回答1:


XSD 1.1 is currently supported by Saxon and by Xerces J. Both should run without trouble under Linux.




回答2:


I found a handy wrapper around Xerces-J: https://www.dropbox.com/s/939jv39ihnluem0/xsd11-validator.jar

java -jar xsd11-validator.jar -sf my.xsd -if my.xml

You can update the Xerces-J lib by unzipping the jar, dropping the new Xerces-J in it, then rezipping it to a jar

Reference

Edit: Updated download link




回答3:


xmllint unfortunately could not support XML Schema 1.1 but alternatively it supports RelaxNG based Schema (including all the advancements similar to the XML Schema 1.1).

Following is the procedure could be used to overcome xmllint limitations:

  1. implement your validation XML Schema version 1.1 based on Oxygen Editor reverse generator (based on already existing XML files). it could be downloaded from here with the 1 month license free

  2. resulting XSD 1.1 file will not be accepted by xmllint with the following error messages:

    xmllint --schema user.xsd --noout user.xml 
    user.xsd:565: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element': Invalid value for maxOccurs (must be 0 or 1).
    user.xsd:741: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element': Invalid value for maxOccurs (must be 0 or 1).
    WXS schema user.xsd failed to compile
    

    however the xml schema could be converted into relaxng schema with the help of RNGConv tool which is a part of the Kohsuke Kawaguchi's MSV project by applying following conversion command:

    java -jar rngconv-20060319/rngconv.jar user.xsd > user.rng
    
  3. resulting relaxng schema file could be used with the xmllint:

    xmllint --relaxng user.rng --noout user.xml 
    user.xml validates
    



回答4:


I answered this question over here at AskUbuntu.
It includes working links to the Xerces-J wrapper xsd11-validator.jar and a comfortable bash script for easy usage.



来源:https://stackoverflow.com/questions/18782706/linux-command-line-tool-validating-xsd-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!