I'm not sure where' I'm going wrong here. I have the following PowerShell error message:
Exception setting "Value": "Cannot set a value on node type 'Document'." At line:18 char:5 + $XMLDoc.$controlSource='$replaceText' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : CatchFromBaseAdapterSetValue
My code is the following:
[xml]$XMLDoc = (Get-Content "C:\process.xml")
foreach($file in Get-ChildItem $outputDirectory) {
$replaceText = <tested working string of the value to replace in the XML doc>
$controlSource = $XMLDoc.SelectNodes("/beans/bean[@id='$bNode']/property[@name='configOverrideMap']/map/entry[@key='sfdc.extractionSOQL']/@value")
$XMLDoc.$controlSource = '$replaceText'
#$XMLDoc -replace ('^"$controlSource"$','^"$replaceText"$') | Out-File $XMLDoc
}
I'm trying to replace a value in an XML file with a string and write the contents of variable $XMLDoc
to the file C:\process.xml
until I get the above message. I can get the part about writing $XMLDoc
to the file, the problem is that I still can't get my string to replace the variable and save. I understand this may be sloppy because I'm doing the same task multiple of times in a foreach
loop, but I'm aiming for functionality at the moment as opposed to optimal.
<beans>
<bean id="MenuGet">
<property name="name" />
<property name="MapOverride">
<map>
<entry key="node.infoblock" value="k4jk2jb54B$T45bt2j5ktb3B%$" />
</map>
</property>
</bean>
<bean id="SystemGet">
<property name="name" />
<property name="MapOverride">
<map>
<entry key="node.infoblock" value="b34t34bhj54b%B#Y$%Bn45ht5h" />
</map>
</property>
</bean>
</beans>