Validating XSD against W3C XML Schema Definition

前端 未结 2 1435
面向向阳花
面向向阳花 2021-01-20 07:20

I am generating some XML Schemas and would like to ensure that our generator is creating valid XML Schema documents (Not XML). I was trying to come up with the code to valid

相关标签:
2条回答
  • 2021-01-20 07:57

    I wouldn't validate an XSD using the approach you described for a couple of reasons, the most important one being that the XSD as a language is weak so in itself it does not capture the full spec. So, most likely, you may validate something that in fact is not valid.

    For XSD validation you have specialized processors; Java has XSOM; follow the user guide.

    0 讨论(0)
  • 2021-01-20 08:03

    I agree with Petru that validating a schema against the schema for schema documents is not a very useful thing to do, because it won't detect all errors in your schema. The only real way to ensure that your schema is valid is to pass it to a schema processor.

    For example, with Saxon

    Processor p = new Processor(true);
    StreamSource ss = new StreamSource(new File('mySchema.xsd');
    p.getSchemaManager().load(ss);
    

    will tell you whether your schema is valid or not.

    0 讨论(0)
提交回复
热议问题