file = "wixmain/generated/DarkOutput.wxs"
template = "wixmain/generated/MsiComponentTemplate.wxs"
output = "wixmain/generated/MSIComponents.wxs"
dark_output = Nokogiri::XML(File.open(file))
template_file = Nokogiri::XML(File.open(template))
#get stuff from dark output
components = dark_output.at_css("Directory[Id='TARGETDIR']")
#where to insert in template doc
template_component_insert_point = template_file.at_css("DirectoryRef[Id='InstallDir']")
#puts template_component_insert_point.methods
template_component_insert_point.children= components.children()
#write out filled template to output file
File.open(output, 'w') { |f| template_file.write_xml_to f }
My generated xml:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="{23E18C28-79B6-4C4A-B40A-9E2AB337197C}" Codepage="1252" Language="1033" Manufacturer="Microsoft" Name="WebSetup" UpgradeCode="{85DD3A3B-4CAD-4288-A612-729555D447B8}" Version="1.0.0">
<Package Compressed="yes" InstallerVersion="200" Languages="1033" Manufacturer="Microsoft" Platform="x86" />
<Binary Id="MSVBDPCADLL" SourceFile="generated/binaries\Binary\MSVBDPCADLL" />
<Binary Id="VSDNETCFG" SourceFile="generated/binaries\Binary\VSDNETCFG" />
----snip out generated stuff ------ ----I want everything in the TARGETDIR node ----
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="C__AD1817F9C64A42F0A14DDDDC82DFC8D9" Guid="{B8CF0FFD-9681-1951-C6C6-7E4152FE28F4}" KeyPath="yes">
<CreateFolder Directory="TARGETDIR" />
</Component>
----snip out a lot more component nodes----
<Component Id="C__06370B56BE12CAF66B15B23C487176A5" Guid="{FD941172-CA4A-8237-B62B-07A136CECCE0}">
<File Id="_06370B56BE12CAF66B15B23C487176A5" Name="Web.config" KeyPath="yes" ShortName="WEB~1.CON" DiskId="1" Source="generated/binaries\File\_06370B56BE12CAF66B15B23C487176A5"/>
</Component>
</Directory>
-----snip out more generated stuff----
My template file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Fragment>
<ComponentGroup Id='MSIComponentGroup'>
</ComponentGroup>
</Fragment>
<Fragment Id='MSIComponents'>
<DirectoryRef Id='InstallDir'>
</DirectoryRef>
</Fragment>
</Wix>
And the output that I get looks like (note the default prepended to the Component nodes):
<?xml version="1.0" encoding="utf-8"?>
<Fragment>
<ComponentGroup Id='MSIComponentGroup'>
</ComponentGroup>
</Fragment>
<Fragment Id='MSIComponents'>
<DirectoryRef Id='InstallDir'>
<default:Component Id="C__AD1817F9C64A42F0A14DDDDC82DFC8D9" Guid="{B8CF0FFD-9681-1951-C6C6-7E4152FE28F4}" KeyPath="yes">
<CreateFolder Directory="TARGETDIR"/>
</default:Component>
<default:Component Id="C__06370B56BE12CAF66B15B23C487176A5" Guid="{FD941172-CA4A-8237-B62B-07A136CECCE0}">
<File Id="_06370B56BE12CAF66B15B23C487176A5" Name="Web.config" KeyPath="yes" ShortName="WEB~1.CON" DiskId="1" Source="generated/binaries\File\_06370B56BE12CAF66B15B23C487176A5"/>
</default:Component>
</DirectoryRef>
</Fragment>
</Wix>