I have looked into this post and found that it is almost exactly what I need to do. However, I am not able to produce the output expected given the suggestion in this post. Basically, I am trying to import </parameter>
elements from an XML ($ManifestFile
) file that contains something like:
<?xml version="1.0" encoding="utf-8"?>
<plasterManifest
schemaVersion="1.1"
templateType="Project" xmlns="http://www.microsoft.com/schemas/PowerShell/Plaster/v1">
<metadata>
<name>PlasterTestProject</name>
<id>4c08dedb-7da7-4193-a2c0-eb665fe2b5e1</id>
<version>0.0.1</version>
<title>Testing creating custom Plaster Template for CI/CD</title>
<description>Testing out creating a module project with Plaster for complete CI/CD files.</description>
<author>Catherine Meyer</author>
<tags></tags>
</metadata>
<parameters>
<parameter name='AuthorName' type="user-fullname" prompt="Module author's name" />
<parameter name='ModuleName' type="text" prompt="Name of your module" />
<parameter name='ModuleDescription' type="text" prompt="Brief description on this module" />
<parameter name='ModuleVersion' type="text" prompt="Initial module version" default='0.0.1' />
<parameter name='GitLabUserName' type="text" prompt="Enter the GitLab Username to be used" default="${PLASTER_PARAM_FullName}"/>
<parameter name="GitLubRepo" type="text" prompt="GitiLab repo name for this module" default="${PLASTER_PARAM_ModuleName}"/>
<parameter name='ModuleFolders' type = 'multichoice' prompt='Please select folders to include' default='0,1'>
<choice label='&Public' value='Public' help='Folder containing public functions that can be used by the user.'/>
<choice label='&Private' value='Private' help='Folder containing internal functions that are not exposed to users'/>
</parameter>
</parameters>
</plasterManifest>
The document ($NewManifestFile
) I'm trying to import into looks like:
<?xml version="1.0" encoding="utf-8"?>
<plasterManifest schemaVersion="1.1" templateType="Project" xmlns="http://www.microsoft.com/schemas/PowerShell/Plaster/v1">
<metadata>
<name>test3</name>
<id>8c028f40-cdc6-40dc-8442-f5256a8c0ed9</id>
<version>0.0.1</version>
<title>test3</title>
<description>SDSKL</description>
<author>NAME</author>
<tags> </tags>
</metadata>
<parameters>
</parameters>
<content>
</content>
</plasterManifest>
The code I have written looks something like:
$ManifestFile = [xml](Get-Content ".PlasterManifest.xml")
$NewManifestFile = [xml](Get-Content $PlasterMetadata.Path)
$NewManifestFile.plasterManifest.metadata.name
$Parameters = $ManifestFile.SelectSingleNode("//plasterManifest/parameters/parameter")
$Parameters
$NewParameters = $NewManifestFile.SelectSingleNode("//plasterManifest/parameters")
#Importing the parameters and content
foreach ($parameter in $Parameters) {
$NewParamElem = $ManifestFile.ImportNode($parameter, $true)
$NewParameters.AppendChild($NewParamElem)
}
[void]$NewManifestFile.save($PlasterMetadata.Path)
Now, it doesn't error out, but it also doesn't import at all. It seems as though some element is not being assigned properly somewhere. I have tried so many alternatives, and this seems to be the only one that is close to what I want. Any suggestions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…