+49 228 5552576-0


info@predic8.com

Compare XML Schema Java API

The following listing shows how to compare two XML Schema documents with Java and the Membrane SOA Model.

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("samples/diff/original/article.xsd");

    Schema schema2 = parser.parse("samples/diff/modified/article.xsd");

    SchemaDiffGenerator diffGen = new SchemaDiffGenerator(schema1, schema2);
    List<Difference> lst = diffGen.compare();
    for (Difference diff : lst) {
      System.out.println(diff.dump());
    }
  }
}

      
Listing 1: CompareSchema.java

After executing you get the output shown in listing 2. It is a List of differences between the two Schema documents.

Element createResponse has changed:
 ComplexType  has changed:
  Sequence has changed:
   Element NewElementForTest added.

ComplexType GetAllType has changed:
 Annotation removed.

Imported schema http://predic8.com/material/1/ has changed:
 Element manufacturer added.
 ComplexType ArticleType has changed:
  Annotation added.
  Sequence has changed:
   Position of element name changed from 1 to 2.
   Position of element description changed from 2 to 3.
   Position of element price changed from 3 to 5.
   Position of element id changed from 4 to 1.
   Element availability added.
 Imported schema http://predic8.com/common/1/ has changed:
  ComplexType PersonType has changed:
   Sequence has changed:
    Element id has changed:
     The type of element 'id' has changed from xsd:string to tns:IdentifierType.
    

Copyright © 2008-2017 predic8 GmbH
Koblenzerstr. 65, 53173 Bonn, Tel. +49 (228) 555 25 76-0