One solution is to sort the artefacts before comparing or merging and this article will show you how.
The artefacts have to be sorted within their respective parent or grandparent, so that BizTalk can import the bindings after sorting and merging. That is, first node must be <ModuleRefCollection> and within that node, <ModuleRef> nodes must be sorted according to the Name attribute. And within each <ModuleRef> there is a <TrackedSchemas> with several <Schema> nodes, to be sorted according to the FullName and RootName attributes. And so on and so forth.
<
ModuleRefCollection
>
ModuleRef
TrackedSchemas
Schema
01.
<?
xml
version
=
"1.0"
encoding
"utf-8"
?>
02.
xsl:stylesheet
03.
04.
xmlns:xsl
"http://www.w3.org/1999/XSL/Transform"
05.
xmlns:msxsl
"urn:schemas-microsoft-com:xslt"
06.
exclude-result-prefixes
"msxsl"
07.
08.
xsl:output
method
"xml"
indent
"yes"
/>
09.
10.
xsl:template
match
"Services"
11.
Services
12.
xsl:apply-templates
select
"Service | @*"
13.
xsl:sort
"@Name"
data-type
"text"
order
"ascending"
14.
</
15.
16.
17.
18.
"ModuleRefCollection"
19.
20.
"ModuleRef | @*"
21.
22.
23.
24.
25.
26.
"TrackedSchemas"
27.
28.
"Schema | @*"
29.
"@FullName"
30.
"@RootName"
31.
32.
33.
34.
35.
"SendPortCollection"
36.
SendPortCollection
37.
"SendPort | @*"
38.
39.
40.
41.
42.
43.
"ReceivePortCollection"
44.
ReceivePortCollection
45.
"ReceivePort | @*"
46.
47.
48.
49.
50.
51.
"@* | node()"
52.
xsl:copy
53.
54.
55.
56.
57.
1.
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
2.
$xslt.Load($xslFilename);
3.
$xslt.Transform($xmlFilename, $outputFilename);
function DoXslTransform ([
string
]$xmlFilename, [
]$xslFilename, [
]$outputFilename)
{
trap [Exception]
Write-Host $_.Exception;
}
###
### Main processing:
if
($args.Length -ne 3)
Write-Output
"Syntax: powershell -f DoXslTransform.ps1 sourceXmlFilename xslFilename destinationFilename"
;
Exit 1;
[
]$xmlFilename = $args[0];
]$xslFilename = $args[1];
]$outputFilename = $args[2];
(!(Test-Path $xmlFilename))
"source file $xmlFilename not found"
exit 1;
(!(Test-Path $xslFilename))
"transform file $xslFilename not found"
"Transforming $xmlFilename with $xslFilename to $outputFilename ..."
DoXslTransform $xmlFilename $xslFilename $outputFilename;
"Done."
@echo off
"%1"
==
""
goto
syntax
"%2"
4.
powershell -f .\DoXslTransform.ps1 %1 .\sort-bindingfile.xslt %2
5.
end
6.
:syntax
7.
echo Syntax: sort-bindingfile.cmd sourcefile.xml destinationfile.xml
8.
:end
To successfully merge your changes without overwriting your colleague’s changes, you get the latest version of the binding file and perform a check out on the file, called MainApplicationBinding.xml.
ren MainApplicationBinding.xml MainApplicationBinding-unsorted.xml
sort-bindingfile.cmd MainApplicationBinding-unsorted.xml MainApplicationBinding.xml
sort-bindingfile.cmd Binding1.xml Binding1-sorted.xml
Sorting the artefacts within a BizTalk binding file is a real time and effort saver. If you wish you can maintain the binding files sorted under version control, and if you dare you can create a check-in trigger that sorts it for you automatically upon check in.
The Powershell script is generic and can run any XSL Transform for you.
Congratulations on the guru award.
Great article.