Sitecore Asked by MartinMace on February 20, 2021
I want to leverage SIF with the Set-Xml task to update the value in the datafolder.config patch file. But so far it seems I am not succeeding in finding the correct XPath due to the XML NS in the file.
I am using the following XPath expression:
//configuration/sitecore/sc.variable[@name='dataFolder']/patch:attribute[@name='value']
For your reference, this is the datafolder.config file shipped with Sitecore 8.2 U7:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<sc.variable name="dataFolder">
<patch:attribute name="value">/data</patch:attribute>
</sc.variable>
</sitecore>
</configuration>
Is it possible to set the value using SIF and an XPath expression? And if so, which XPath might do the trick? Any help is appreciated.
Okay, I got it working. The problem was with the inability of the SetXml SIF task to provide an XML NS.
So I created a custom task based on the SetXml task with an extra parameter to provide the namespace, the SIF configuration (in my case) then becomes as follows:
"SetDataFolder": {
"Type": "SetXml",
"Params": {
"FilePath": "[joinpath(variable('Site.WebsiteFolder'), 'App_Config', 'Include', 'DataFolder.config')]",
"XPath": "//configuration/sitecore/sc.variable[@name='dataFolder']/patch:attribute[@name='value']",
"Namespace": [
{
"patch": "http://www.sitecore.net/xmlconfig/"
}
],
"Value": "[parameter('DataFolder')]"
}
}
To accomplish this, just copy the complete SetXml task from the SIF library, make the necessary modifications to support the namespace in the Select-XML method, and include it in your module loading and be sure to register it using an overwrite of the out-of-the-box module using
Register-SitecoreInstallExtension -Command Invoke-SetXmlTaskEx -As SetXml -Type Task -Force
Hopefully this will help anyone else stumbling into the same problem until it hopefully becomes part of the official SIF version.
Correct answer by MartinMace on February 20, 2021
As Martine Said you either need to create Extension for SetXml to support namespaces, or in simple cases like DataFolder you can use some trick like this:
"CopyDataFolderConfig": {
"Type": "Copy",
"Params": {
"Source": "[joinpath(variable('Site.PhysicalPath'), 'App_Config','Include','Examples','DataFolder.config.example')]",
"Destination": "[joinpath(variable('Site.PhysicalPath'), 'App_Config','Include', 'DataFolder.config')]"
}
},
"PatchDataFolder": {
"Description": "Changing Data Folder.",
"Type": "SetXml",
"Params": {
"FilePath": "[joinpath(variable('Site.PhysicalPath'), 'App_Config','Include', 'DataFolder.config')]",
"XPath": "//configuration/sitecore/sc.variable[@name='dataFolder']/*",
"Value": "[variable('Site.DataFolder')]"
}
}
using '*' as a selector in such cases is not generaly a good idea, but in this case it wont cause any problem.
Answered by Ghodrat Ashournia on February 20, 2021
2 Asked on January 5, 2022 by nutsandbolts
2 Asked on December 30, 2021 by manideep-yechuri
2 Asked on December 20, 2021 by manoj-sreekumar
1 Asked on December 18, 2021
1 Asked on December 13, 2021 by jyoti
1 Asked on December 11, 2021 by arvind-gehlot
1 Asked on December 11, 2021 by jeyanth-praveenkumar
1 Asked on December 11, 2021 by nali
1 Asked on December 9, 2021 by vlad-iobagiu
2 Asked on December 7, 2021 by grilosape
2 Asked on December 7, 2021 by johnny-lopez
1 Asked on December 5, 2021
1 Asked on December 2, 2021
1 Asked on November 27, 2021 by amitabh-vyas
1 Asked on November 27, 2021 by user3621
0 Asked on November 24, 2021
1 Asked on November 22, 2021 by kalikrishna
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP