I have the following XML node in my XML document that I need to update:
<ImageUrl>xxx.xxx.com/imageeditor/X.jpg</ImageUrl>
With the following:
<ImageUrl>xxx.xxx.com/image/getdvimage/X/1/false/200/200/</ImageUrl>
where "X" in the first string is a number (9808 for example) and needs to be in the place of "X" in the second node. This is the only node called ImageUrl in the document, and I need to update the whole document this way. So I need help finding the X in the node and replacing it with the X in the updated node and saving the file.
I am trying this code:
[xml]$xml = Get-Content 'D:\temp\feed.xml'
Foreach ($item in (Select-XML -Xml $xml -XPath '//ImageUrl'))
{
$oldValue = $item.node.innertext #need to get the value from the last "/" to the .jpg value
$newValue = [string]::Format('xxx.xxx.com/image/getdvimage/{0}/1/false/200/200/',$oldValue) #place the $oldValue into the new string here
$item.node.Name = ???
}
$NewPath = 'D:\temp\FeedUpd.xml'
$xml.Save($NewPath)
Here is the XML I am using:
<Product>
<ExternalId>2127</ExternalId>
<Name>test</Name>
<Description>
<![CDATA[
desc
]]></Description>
<BrandExternalId>xxx</BrandExternalId>
<CategoryExternalId>Foo</CategoryExternalId>
<ProductPageUrl><![CDATA[xxx.com/2127]]></ProductPageUrl>
<ImageUrl>xxx.com/imageeditor/2127.jpg</ImageUrl>
<ModelNumbers>
<ModelNumber>2127</ModelNumber>
</ModelNumbers>
<ManufacturerPartNumbers>
<ManufacturerPartNumber>2127</ManufacturerPartNumber>
</ManufacturerPartNumbers>
<UPCs>
<UPC>841101002711</UPC>
</UPCs>
</Product>
If I could pull the Model Number to insert into the new string {0} I wouldn't have to parse the old ImageUrl, just insert the Model into the string. How would I grab the <ExternalId> and the <ImageUrl> in the loop to replace?