Linux command line tool validating XSD 1.1?

2019-07-23 10:05发布

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

Xmllint does not validate version 1.1.

4条回答
放荡不羁爱自由
2楼-- · 2019-07-23 10:22

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楼-- · 2019-07-23 10:27

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楼-- · 2019-07-23 10:34

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

查看更多
手持菜刀,她持情操
5楼-- · 2019-07-23 10:37

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.

查看更多
登录 后发表回答