XPath statement to replace values
Posted on 2006-06-28
Platform: Windows, VB.Net 2003
I have to process an incoming XML file by replacing certain element contents with other strings. For example:
incoming data: <anType>Conformance_1</anType>
needs to change to: <anType>Conf1</anType>
This is a simple string replacement operation, but it's a kludge from hell to change the entire XML file to a string variable to replace these substrings.
But, we have around 100 of these valid values that we must change in the XML doc. Each valid value may occur multiple times. I wanted to use an embedded stylesheet but VS2003 does not support XslCompiledTransform() like VS2005 does.
So now I am trying the XPathNavigator. What I need is an XPath statement I can use to 1) select all the elements in the XML document that contain the target string, and then 2) replace each occurrence with the correct replacement string.
Whatever solution I get, I will need to implement around 100 times.