Search code examples
javaxmlwsdlcanonicalization

How to canonicalize WSDL files in Java?


I need to find differences in two WSDL files. I started by pretty-printing them like here, but I see there are same things (e.g. complexTypes) in the two files defined (for whatever stupid reason) in a different order. I want to canonicalize the files further, so I can later use things like standard diff to find the differences.

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.


Solution

  • I ran through the tree recursively and sorted all children of nodes matching schema|wsdl:binding|wsdl:portType|wsdl:types|wsdl:definitions. I used this answer for pretty-printing the output. For whatever reason format.setLineWidth(65); doesn't work, so I had to join the lines using replaceAll("\\s*\n\\s*(?=[^\\s<])", " "). It seems to work fine.