I am trying to match the Location
tag in an XML and replace "\" with "\\" in the xml content only for the Location tag ,can anyone provide guidance on how to do that?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Matchlocationreplacebackslash
{
class Program
{
static void Main(string[] args)
{
string pattern = "<Location>(.*?)</Location>";
string xmlcontent = @"<SoftwareProductBuild>
<BuildSource>QCA_DEV_POSTCOMMIT</BuildSource>
<BuiltBy>wbibot</BuiltBy>
<CreatedBy>wbibot</CreatedBy>
<Name>BTFM.CHE.2.1.2-00091-QCACHROM-1_NO_VARIANT</Name>
<Status>Approved</Status>
<BuiltOn>2017-08-28T13:00:04.345Z</BuiltOn>
<Tag>BTFM.CHE.2.1.2_BTFM.CHE.2.1.2-00091-QCACHROM-1_2017-08-28T13:00:04.345Z</Tag>
<SoftwareImageBuilds>
<SoftwareImageBuild>
<Type>LA</Type>
<Name>BTFM.CHE.2.1.2-00091-QCACHROM-1_NO_VARIANT</Name>
<Location>\\snowcone\builds676\INTEGRATION\BTFM.CHE.2.1.2-00091-QCACHROM-1</Location>
<Variant>NO_VARIANT</Variant>
<LoadType>Direct</LoadType>
<Target>NO_VARIANT</Target>
<SoftwareImages>
<SoftwareImage>
<Name>BTFM.CHE.2.1.2</Name>
<SoftwareProducts>
<SoftwareProduct>
<Name>MSM8998.LA.1.9</Name>
<BaseMeta>CI_MSM8998.LA.1.9-16991-INT-2</BaseMeta>
</SoftwareProduct>
</SoftwareProducts>
</SoftwareImage>
</SoftwareImages>
</SoftwareImageBuild>
</SoftwareImageBuilds>
</SoftwareProductBuild>";
Match match = Regex.Match(xmlcontent, pattern); //Match location
//Replace "\" with "\\" in the xml content with the match
Console.ReadLine();
}
}
}