How to verify that one XSD schema is a subset of another XSD schema?

后端 未结 4 1575
轮回少年
轮回少年 2021-02-04 15:43

How can I verify that one XSD schema is a subset of another XSD schema?

We are creating a system-of-systems application using a collection of \"blueprint\" XSD schemas (

4条回答
  •  醉酒成梦
    2021-02-04 16:26

    Since currently there is no available solution of validating/checking schema against another schema, looks like we have to use workarounds. Below is my attempt.

    Restating the problem:

    Identify whether all the data types defined in a subset schema exists and are within the (less stricter) bounds of what is defined in a "blueprint" schema.

    A possible solution:

    1. First piece of (obvious) information is that Schema allows us to create XML instances (what does that even mean?! see 2.).
    2. Another piece of (not so obvious) information we have is that XML schema itself can be a "subset instance" - what I mean by that is: if you were to reverse engineer a schema from your XML instance, then you have a subset schema (this statement is not always true if you do not have "lists" or choice elements or other “confines”, then the reversed engineered subset schema will map exactly to the "blueprint" schema).

    So, using this knowledge, we can construct a solution:

    Create all possible XML instances of a subset schema (doing this step programmatically can be a challenge), and validate these XML instances against the "blueprint" schema.

    But how you know that the subset schema is a subset of a "blueprint" schema? Well, since you created all possible XML instances of a subset schema, it covered all the data types that are there in a subset schema. And validating these XML instances against the "blueprint" schema, inherently is checking whether the data types exists and all is within the bounds of what is defined in the "blueprint" schema. Hence, identifying that your subset schema is indeed a subset of a "blueprint" schema.

    I know its not an ideal solution, but hope this helps given that there is no simple way available to do what you are asking.

提交回复
热议问题