问题
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. complexType
s) 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.
回答1:
You can download a Java program from http://www.jclark.com/xml/ which converts XML to Canonical XML. This should be applicable to WSDL files too.
回答2:
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.
来源:https://stackoverflow.com/questions/6446904/how-to-canonicalize-wsdl-files-in-java