Merge 2 XML file with Powershell

Tom AUBRY 1 Reputation point
2022-10-04T11:57:06.147+00:00

Hello,
I've been trying for a few weeks to merge 2 XML files in powershell but I don't know anything about it.
Here are the two files that my script retrieves:
https://wcf.tourinsoft.com/Syndication/3.0/cdt85/953fa134-788f-441d-bc2e-c4888f9c1a4d/$metadata
https://wcf.tourinsoft.com/Syndication/3.0/cdt85/2a2f82af-f82f-4831-b958-798666a7e35f/$metadata

I did this:
$WebRequest = New-Object System.Net.WebClient
$WebRequest.DownloadFile([System.Uri]'https://wcf.tourinsoft.com/Syndication/3.0/cdt85/953fa134-788f-441d-bc2e-c4888f9c1a4d/$metadata', "C:\Users\t-aubry\Desktop\tourinsoft\flux\Restaurants\test1.xml")
$WebRequest.DownloadFile([System.Uri]'https://wcf.tourinsoft.com/Syndication/3.0/cdt85/2a2f82af-f82f-4831-b958-798666a7e35f/$metadata', "C:\Users\t-aubry\Desktop\tourinsoft\flux\Restaurants\test2.xml")
Get-Content C:\Users\toto\Desktop\tourinsoft\flux\test1.xml, C:\Users\toto\Desktop\tourinsoft\flux\test2.xml | Out-File C:\Users\toto\Desktop\tourinsoft\flux\merge.xml

But this copies file 2 after file 1. I doubt that this is the desired structure...

Thanks in advance, I'm lost ;)

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. M. Jenne 75 Reputation points
    2023-01-25T05:36:28.3233333+00:00

    I would suggest looking at what is going to consume this "aggregation" you are trying to do and see if there are other options.

    These two XML files use ( slightly ) different schemas, so you will never be able to just merge them together until you take a crash course on XML, namespaces and the XML DOM.

    About the best you could do is create a PSCustomObject that represents a union of the data from each file.

    Good Luck,

    MJ

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.