How to compare 2 xsd schema files for equivalent functionality

I would like to compare the 2 XSD schemes A and B to determine that all instance documents valid for scheme A will also be valid for scheme B. I hope to use this to prove that although schemes A and B are “different”, they are actually the same. Examples of differences that this would not have caused are the schemas used by types A, and the schema B declares all its inline elements.

I found many people talking about smart tools like diff, but they would argue that the two files are different from each other because they have different text, but the resulting structure is the same. I found some links on XSOM, but I'm not sure if this will help or not.

Any thoughts on how to proceed?

+6
source share
2 answers

Membrane SOA Model - Java API for WSDL and XML Schema

package sample.schema; import java.util.List; import com.predic8.schema.Schema; import com.predic8.schema.SchemaParser; import com.predic8.schema.diff.SchemaDiffGenerator; import com.predic8.soamodel.Difference; public class CompareSchema { public static void main(String[] args) { compare(); } private static void compare(){ SchemaParser parser = new SchemaParser(); Schema schema1 = parser.parse("resources/diff/1/common.xsd"); Schema schema2 = parser.parse("resources/diff/2/common.xsd"); SchemaDiffGenerator diffGen = new SchemaDiffGenerator(schema1, schema2); List<Difference> lst = diffGen.compare(); for (Difference diff : lst) { dumpDiff(diff, ""); } } private static void dumpDiff(Difference diff, String level) { System.out.println(level + diff.getDescription()); for (Difference localDiff : diff.getDiffs()){ dumpDiff(localDiff, level + " "); } } } 

After execution, you will get the result shown in Listing 2. This is a list of the differences between the two schema documents.

 ComplexType PersonType has changed: Sequence has changed: Element id has changed: The type of element id has changed from xsd:string to tns:IdentifierType. 

http://www.service-repository.com/ offers an online XML Schema Version Comparator that displays a report of the differences between the two XSDs that appear to be produced from the SOA Membrane Model.

+4
source

My approach to this was to canonicalize the representation of an XML schema.

Unfortunately, I can also tell you that, unlike canonicalization of XML documents (used, for example, to calculate a digital signature), it is not so simple or even standardized.

So basically you have to convert both XML schemas to a “canonical form” - no matter what tool you create or use, thinks that form is, and then do a comparison.

My approach was to create a set of XML schemas (maybe more than one file if you have more namespaces) for each root element that I need, since it was easier for me to compare XSDs created using the style of the Russian doll, starting with the PSVI Model .

Then I used options such as members of the auto-substitution substitution group, as well as the replacement of substitution groups to choose from; removal of "unnecessary" XML schema sequences, folding options with one option or moving minOccurs / maxOccurs around for individual composer elements, etc.

Depending on which features of the comparison tool are XSD-compatible, or you plan to build, you may also need to reorder particles under composers such as xsd: choice or xsd: all; etc.

In any case, what I learned after all this, it was very difficult to create a tool that would work for all the “cool” XSD functions there ... One test case, which I remember with love, concerned various xsd: any content.

I really wonder if things have changed since then ...

+3
source

Source: https://habr.com/ru/post/902512/


All Articles