简体   繁体   English

如何在Java中规范化WSDL文件?

[英]How to canonicalize WSDL files in Java?

I need to find differences in two WSDL files. 我需要找到两个WSDL文件中的差异。 I started by pretty-printing them like here , but I see there are same things (eg complexType s) in the two files defined (for whatever stupid reason) in a different order. 我从这里像这样漂亮地打印它们开始 ,但是我看到在两个定义的文件中(出于任何愚蠢的原因)以不同的顺序有相同的事物(例如complexType )。 I want to canonicalize the files further, so I can later use things like standard diff to find the differences. 我想进一步规范化文件,因此以后可以使用诸如标准diff类的东西来查找差异。

No idea if there's a defined canonical form for WSDL, I know there's Canonical XML , but I need to go a bit further and sort all the things whose order doesn't matter. 不知道WSDL是否有定义的规范形式,我知道有Canonical XML ,但是我需要进一步讲解并排序所有顺序无关紧要的东西。

You can download a Java program from http://www.jclark.com/xml/ which converts XML to Canonical XML. 您可以从http://www.jclark.com/xml/下载Java程序,该程序会将XML转换为Canonical XML。 This should be applicable to WSDL files too. 这也应该适用于WSDL文件。

I ran through the tree recursively and sorted all children of nodes matching schema|wsdl:binding|wsdl:portType|wsdl:types|wsdl:definitions . 我递归地遍历了树,并对与schema|wsdl:binding|wsdl:portType|wsdl:types|wsdl:definitions匹配的节点的所有子节点进行排序。 I used this answer for pretty-printing the output. 我用这个答案来漂亮地打印输出。 For whatever reason format.setLineWidth(65); 无论出于何种原因format.setLineWidth(65); doesn't work, so I had to join the lines using replaceAll("\\\\s*\\n\\\\s*(?=[^\\\\s<])", " ") . 不起作用,因此我不得不使用replaceAll("\\\\s*\\n\\\\s*(?=[^\\\\s<])", " ") It seems to work fine. 似乎工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM