XML/WSDL 比较工具 [英] XML/WSDL Comparison tool

查看:42
本文介绍了XML/WSDL 比较工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于经常使用网络服务的人来说,他们会不时更新,这并不奇怪.而且您始终需要跟踪这些更新的变化.

在我的特殊情况下,我处理由 WSDL 定义的 Web 服务,并获得基于此 WSDL 生成的类.

但是在从更新的 WSDL 重新生成类之前,我想看看 WSDL 中发生了什么变化并确定更改量 - 看看我应该准备什么.

不幸的是,如果我只比较新旧版本的 .wsdl 文件,它并不总是能很好地工作,原因之一 - wsdl 内容可以重新排序(内部重构).这就是寻找更多语义工具的原因.

我尝试过 Oxygen XML Diff 工具,但它对我来说效果不佳.

我正在寻找一种工具,该工具将采用两个 XML 并只为我带来语义差异,例如:

  • 添加了元素 A
  • 将子元素 b7 添加到元素 B

为了让这个工作,我猜该工具必须加载并深入分析结构,Oxygen XML Diff 声称做得很好,但它只是文本文件比较的改进版本.

您能否为此推荐一个工作,特别是查看基于 WSDL 的网络服务的更新.

更新 1:新想法是比较生成的源而不是 WSDL.

谢谢.

解决方案

http://membrane-soa.org 有一个 Java API 用于比较 WSDL 在他们的 SOA 模型.

package sample.wsdl;导入 java.util.List;导入 com.predic8.wsdl.*;导入 com.predic8.wsdl.diff.WsdlDiffGenerator;导入 com.predic8.soamodel.Difference;公共类比较WSDL {公共静态无效主(字符串 [] args){相比();}私有静态无效比较(){WSDLParser 解析器 = 新的 WSDLParser();定义 wsdl1 = parser.parse("resources/diff/1/article.wsdl");定义 wsdl2 = parser.parse("resources/diff/2/article.wsdl");WsdlDiffGenerator diffGen = new WsdlDiffGenerator(wsdl1, wsdl2);列表<差异>lst = diffGen.compare();for (Difference diff : lst) {转储差异(差异,");}}私有静态无效转储差异(差异差异,字符串级别){System.out.println(level + diff.getDescription());对于(差异localDiff:diff.getDiffs()){dumpDiff(localDiff, level + " ");}}}

<块引用>

执行后你得到清单 2 所示的输出.它是一个 List两个 WSDL 文档之间的差异.

Port ArticleServicePTPort 已删除.添加了端口文章ServicePTPort2.操作创建删除.添加了 create2 操作.架构 http://predic8.com/wsdl/material/ArticleService/1/已更改:元素 createResponse 已更改:ComplexType 已更改:顺序变了:添加了元素 NewElementForTest.

对于该工具的输出示例,http://www.service-repository.com/ 提供了一个在线 WSDL 比较器工具,返回两个 WSDL 之间差异的报告.该报告不是简单的 XML 差异.

There is no surprise for those who work with web-services a lot that they get updated from time to time. And you always need to track changes of these updates.

In my particular case I deal with web service defined by WSDL and I get classes generated based on this WSDL.

But before regeneration of classes from updated WSDL I would like to see what was changed in WSDL and determine amount of changes - to see what should I be prepared for.

Unfortunately, if I compare just .wsdl files of new and old version it doesn't always work very well for one reason - wsdl contents can be reordered (refactored internally). That's the reason to find more semantic tool.

I've tried Oxygen XML Diff tool but it doesn't also work well for me.

I am looking for a tool which will take two XMLs and bring me only semantic differences, e.g.:

  • Element A added
  • Added subelement b7 to element B

For this to work I guess the tool must load and deeply analyze the structure, Oxygen XML Diff was claim to do it well, but it just an improved version of text files comparison.

Could you recommend a working to for that, in particular to see updates in web-services based on WSDL.

UPDATE 1: New Idea is to compare generated sources rather than WSDLs.

Thank you.

解决方案

http://membrane-soa.org has a Java API for comparing WSDL in their SOA Model.

package sample.wsdl;

import java.util.List;
import com.predic8.wsdl.*;
import com.predic8.wsdl.diff.WsdlDiffGenerator;
import com.predic8.soamodel.Difference;

public class CompareWSDL {

  public static void main(String[] args) {
    compare();
  }

  private static void compare(){
    WSDLParser parser = new WSDLParser();

    Definitions wsdl1 = parser.parse("resources/diff/1/article.wsdl");

    Definitions wsdl2 = parser.parse("resources/diff/2/article.wsdl");

    WsdlDiffGenerator diffGen = new WsdlDiffGenerator(wsdl1, wsdl2);
    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 WSDL documents.

Port ArticleServicePTPort removed.
Port ArticleServicePTPort2 added.
Operation create removed.
Operation create2 added.
Schema http://predic8.com/wsdl/material/ArticleService/1/ has changed:
  Element createResponse has changed:
    ComplexType  has changed:
      Sequence has changed:
        Element NewElementForTest added.

For an example of the output from the tool, http://www.service-repository.com/ offers an online WSDL Comparator tool that returns a report of the differences between two WSDL. The report is not a simple XML diff.

这篇关于XML/WSDL 比较工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆