Thursday, March 13, 2014

Linq to replace Dictionary values with XML formed tag values.

static void Main(string[] args)
{
 
IDictionary<string, string> placeHolder = new Dictionary<string, string>();

placeHolder.Add("#FirstName#","Phil");

placeHolder.Add("#MiddleName#", "J");

placeHolder.Add("#LastName#", "Haack");
        string parsedXmlString=GetParsedTemplate(@"



#FirstName#

#MiddleName#

#LastName#





", placeHolder);}
 
 
 

public static string GetParsedTemplate(string wellFormedXML, IDictionary<string, string> placeHolder)
{

placeHolder.AsEnumerable().ToList().ForEach(t => wellFormedXML = wellFormedXML.Replace(t.Key, t.Value));

return wellFormedXML;


}
Post a Comment