I am doing some export to XML of uninstall data, mostly for Autodesk products. And Autodesk has a habit of duplicating things, like multiple versions of the same software, with different GUIDs, but that can't be installed side by side, and the old GUID isn't deleted by installing the update. And the way my XML works, I abstract the GUID to a variable in the uninstall string, so I can have one <UninstallProgram>
element with the data needed to find and delete all instances. But of course I FIND that data in the registry twice, so my current code creates two elements.
Net result is I can have this element twice.
<UninstallProgram id="Lighting Analysis for Revit 2023">
<Search>Lighting Analysis for Revit 2023</Search>
<Filter>UninstallString -like *AdODIS*</Filter>
<Resource>C:\ProgramData\Autodesk\ODIS\metadata</Resource>
<Executable>C:\Program Files\Autodesk\AdODIS\V1\Installer.exe</Executable>
<Arguments>-i uninstall --trigger_point system -m [Task~Resource]\[Task~GUID]\bundleManifest.xml -x [Task~Resource]\[Task~GUID]\SetupRes\manifest.xsd -q</Arguments>
</UninstallProgram>
What I am wondering is, is there an easy way to take an element variable, that has been created but not yet appended, and search for any other element that is exactly the same, including all attributes, child elements and element text? I know I can search for an element with the same ID, but if Autodesk does something weird and I somehow build a second element with the same ID but different contents, I want to append that so I can find it and start addressing my code to find the new condition Autodesk has so kindly provided. I don't want to spend too much time or code. I have already looked at just iterating through the current XML, converting every single element to a string representation and comparing that to the string representation of the element being evaluated, but that gets ugly performance wise, since the current XML gets larger and larger, and I would be doing this comparison hundreds of times. And the issue arrises rarely enough that just manually editing the XML isn't THAT big of a deal. Ideally what I want is something that is part of XPath, so highly optimized, that allows for a conditional like
if ($xmlSelectSingleNode("NotMatch $newUninstallElement")){
[Void]$rootElement.AppendChild($newUninstallElement)
}
