Looking to read a list of xml elements (as xpaths) & their new values from a csv file -> and then, look into an existing xml file to replace whatever xml elements are to be updated, with the new values on the given xpaths.
I got the values for the xpaths I need to change in the big xml by online parsing it. There can/will be any number of values to replace at one time, so I can't hard-code these into the powershell - it will need to read each set of changes required each time - from a file (the csv), I am suggesting.
One xpath target to replace a value is is :
/configuration/services/objects/object/app-args/list/value[0]/text()
So I have the csv line as:
"/configuration/services/objects/object/app-args/list/value[0]/text()","new value"
I then call a fn to replace this xpath with the new value, in the xml.
I am struggling on just that one line, where the "-" in app-args xpath string above, is being parsed and somehow cutting the xpath string short there, and therefore tripping out the replace. I can't change the node names in the xml - not an option.
I can browse the xml structure in powershell when I load it:
$xml = [xml](Get-Content "C:\temp\big.xml")
So autocomplete browsing on prompt, I can then see that:
PS c:\temp> $xml.configuration.services.objects.object.'app-args'.list.value[0]
will show me the correct "replace this value 1" in the xml.
But I can't get the xpath phrasing correct in the csv to replace this node. How can I read that node with the "-" in the name, from a file? I've tried /"app-args"/ and a host of other escape chars but out of ideas for now. Use something other than csv?
No experience with xpath before and it's really killing me!
Ref: (simplified) xml with problem area is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<spring xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net ../../../../lib/spring.net/spring-objects-1.1.xsd">
<context>
<resource uri="config://spring/objects" />
<context name="services">
<resource uri="config://spring/services/objects" />
</context>
</context>
<objects xmlns="http://www.springframework.net" default-autowire="constructor">
<object name="SomeServicefactory" type="ServiceFactory" />
</objects>
<services>
<objects xmlns="http://www.springframework.net" default-lazy-init="true">
<object name="SystemConfiguration" type="SystemConfiguration">
<app-args name="ConfigCodes">
<list element-type="string">
<value>old value</value>
<!-- Automate me -->
<!-- use case, assume default value as per above, allow the powershell module to override this -->
<value>old value</value>
<!-- Automate me -->
<!-- use case, assume default value as per above, allow the powershell module to override this -->
</list>
</app-args>
</object>
</objects>
</services>
</spring>
</configuration>
And the most simple csv I am using is (xpath,new value for it):
"/configuration/services/objects/object/app-args/list/value[0]/text()","new value 1"
"/configuration/services/objects/object/app-args/list/value[1]/text()","new value 2"