I have a directory of very large XML files with a structure like 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 an easy way to combine the files of these files (* .xml) 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 of 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>
It works, but not as flexible as I want. As a newbie to PowerShell (version 2), looking to learn new best practices for working with XML in PowerShell, I wonder what is the easiest and cleanest way for PowerShell to combine the structure of XML documents into one?
Cheers, Joachim
Yooakim
source share