I've been trying to replace a specific value from an xml document in memory before creating a message log of the XML.
I've managed to do a replace, but the Regex replace method seems to replace other items as well.
I've had to make this a little more funky than I would have liked but the elements within the document can contain different XML namespaces...
string pattern = "(<).*?(ElementName>).*?(<\\/).*?(ElementName>).*?";
string replacementPattern = "(<).*?(ReplacedElementName>)xxxxxxxxxxxxxx(<\\/).*?(ReplacedElementName>).*?";
string messageToLog = Regex.Replace(messageToSanitise, pattern, replacementPattern);
Can anyone point out where I'm going wrong?
[Update 16:11 BST 09/08/2013]
Thanks Dash, I tried to do that, but then I realised that the object Contains an xml and isn't actually an xml document itself, looks like the object has some headers, with the xml is within a document envelope. Ideally I don't want to lose any information (including the headers) before logging. There will always be 1 or 2 occurences of the element I am trying to change never more and never less than 1.