我想比较 2 个 XSD 模式 A 和 B,以确定对模式 A 有效的所有实例文档也对模式 B 有效。我希望用它来证明即使模式 A 和 B 是“不同的”,它们也是有效的相同。这不会触发的差异示例是架构 A 使用类型,而架构 B 声明它的所有元素内联。
我发现很多人都在谈论“智能”差异类型工具,但这些人会声称这两个文件不同,因为它们具有不同的文本,但结果结构是相同的。我发现了一些对 XSOM 的引用,但我不确定这是否有帮助。
关于如何进行的任何想法?
最佳答案
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 executing you get the output shown in listing 2. It is a List of 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/提供在线XML Schema Version Comparator显示两个 XSD 之间差异的报告的工具,这些 XSD 似乎是从膜 SOA 模型生成的。
关于xsd - 如何比较 2 个 xsd 架构文件的等效功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8290763/