Need to make XML generation code dynamic

Code:

//Takes input as values separated by ///
string csvString = "row11,row12,row13///row21,row22,row23///row31,row32,row33";

// Read into an array of strings.
string[] source = csvString.Split(new string[] { "///" }, StringSplitOptions.None);

//Generate XML based on the ',' and source array.
// Note that dbTemplate here is the comma separated template field values (check below)
XElement cust = new XElement("Root",
                    from str in source
                    let fields = str.Split(',')
                    select new XElement("Client",
                        new XElement(dbTemplate[0], fields[0]),
                        new XElement(dbTemplate[1], fields[1]),
                        new XElement(dbTemplate[2], fields[2])
                        )
                );


string result=cust.ToString();

Logic: I have got a table in SQL db having 2 columns: IssueType and template and written code to fetch the template based on IssueType .

IssueType      Template
Client    Name,Phone,Address
Claim     Name,Type,Date,HandlerName,SettledDate
Incident  Place,Cost,Name,Date

Above code generates XML output for 3 fixed csv values and corresponding 3 fixed IssueType->Tempalte values (ie:IssueType=Client). I want to make the code dynamic (Presently it will only work for IssueType=Client ie:having 3 template values). The no. of values in comma separated CSV will always be equal to the number of comma separated values coming from respective IssueType column from db. Please guide.

Jon Skeet
people
quotationmark

I'm having a hard time following the question, but I think you just want to change your select clause to:

select new XElement("Client",
    dbTemplate.Zip(fields, (name, value) => new XElement(name, value)))

people

See more on this question at Stackoverflow