I have replacement xml that has placeholder and its value. I have XML string where I need to search for placeholder and replace that with the value.
for example,
Placeholder XML:
<PlaceHolders>
<PlaceHolder placeholder="PD1" value="value1" />
</PlaceHolders>
XML
<customers>
<customer avatarURL="PD1"/>
</customers>
What is the best way to replace “PD1” with value “value1”?
Here’s one way to do it using XPath. This will replace a single placeholder with its correct value. You would need to loop through and do this once for each placeholder. This will replace the placeholders found in any attribute of any element in the XML:
If, however, you also need to replace it in the text value of elements as well (e.g.
<customer>PD1</customer>), then you would need to change the XPath to find either attributes or element text values: