I am building a comparison engine script in PowerShell and one of the things I need to be able to compare are XML files. When I use the native PowerShell compare-object it returns 0 differences, yet if I grab the outerxml (text representation) and diff that I do get differences. Unfortunately this puts everything into one long string so is not useful.
I then tried using the XmlDiffPatch library from Microsoft, however if I use the sample program or the library within PowerShell, my 2 XML files fail with the exception:
$d.Compare("c:\scripts\ps\ref.xml", "c:\scripts\ps\tgt.xml", $false)
Exception calling "Compare" with "3" argument(s): "Length cannot be less than zero.
Parameter name: length"
At line:1 char:1
+ $d.Compare("c:\scripts\ps\ref.xml", "c:\scripts\ps\tgt.xml", $false)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException
Without access to the source code for this library I have no idea what is going on other than a bug. The 2 XML's parse fine in IE, so I know they are valid XML.
Has anyone else seen this before? How did you solve it?