I have a directory of very large XML files with a structure as this:
file1.xml:
<root>
<EmployeeInfo attr="one" />
<EmployeeInfo attr="two" />
<EmployeeInfo attr="three" />
</root>
file2.xml:
<root>
<EmployeeInfo attr="four" />
<EmployeeInfo attr="five" />
<EmployeeInfo attr="six" />
</root>
Now I am looking for a simple way to merge these files (*.xml) files into one output file:
<root>
<EmployeeInfo attr="one" />
<EmployeeInfo attr="two" />
<EmployeeInfo attr="three" />
<EmployeeInfo attr="four" />
<EmployeeInfo attr="five" />
<EmployeeInfo attr="six" />
</root>
I was thinking about using pure XSLT such as this one:
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Container>
<xsl:copy-of select="document('file1.xml')"/>
<xsl:copy-of select="document('file2.xml')"/>
</Container>
</xsl:template>
</xsl:stylesheet>
This works but isn’t as flexible as I want. Being a novice with PowerShell (version 2) eager to learn new best pracctices of working with XML in PowerShell I am wondering what is the simplest, purest PowerShell way of merging the structre of XML documents into one?
Cheers,
Joakim
While the XSLT way to do this is pretty short, so is the PowerShell way:
Hope this helps,