But it really depends on how you want the output to displayed/used. What do you want to do next with the information, or how do you want it specifically presented?
Thanks Phatmandrake for your quick response. Based on the differences in the xml file, I need to run another business logic.
The code you shared will work only if I have one node available.
I am going to have a huge xml file with multiple nodes present.
If I am understanding you correctly, then you want to know which Child Nodes of the FileName Nodes are not present in the Difference Object, but you also want to relate that to the Name attribute of the corresponding Filename parent node. If this is the case and you want to be able to actually work with Powershell Objects after the match, then I would convert your text XML to XElement Objects, and turn them into custom objects with the properties you need to examine, then compare those objects to each other.
It's important to note that when you use Compare-Object it simply looks for any identical matches, regardless of position unless you specify the SyncWindow parameter, which will then enforce position based comparison.
Compare-Object examines adjacent objects when it doesn't find the object in the same position in a collection. The default value is [Int32]::MaxValue, which means that Compare-Object examines the entire object collection.
I don’t know what other restraints you may be looking for in comparing the differences between your XML, but if you’re just looking to see which child nodes do not exist for parent nodes of type `FileName’, then the code above should work for you.