You can do it with a series of Regex.Replaces:
// 1) Replace closing and opening tags with commas.// Include quotes in case any values have commas in them.var result = Regex.Replace(input, @"(\S)<\/[^>]*>\s*<[^>]*>(\S)", "$1\",\"$2");// 2) Put in CSV line breaks and remove xml delimiters, include leading and trailing quotesresult = Regex.Replace(result, @"<\/[^>]*>\s*<\/Item>\s*<Item>\s*<[^>]*>", "\r\n");// 3) Remove remaining tags and trim any whitespaceresult = Regex.Replace(result, @"\s*<.*>\s*", "");// 4) put in header row and first and last quotesresult = "Name,Count,Price,Comment,Artist,Publisher,Genre,Year,ProductID,\r\n\""+ result +"\"";
is this a better solution than other solutions? No. It's brittle and would break easily.
Here are the Regex steps visually: