In my application I build an XML file with this code using StringBuilder:
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine);
sb.Append(String.Format("<{0}>{1}", _pluralCamelNotation, Environment.NewLine));
for (int index = 0; index < 3; index++)
{
sb.Append(String.Format("\t<{0}>{1}", _singularCamelNotation, Environment.NewLine));
foreach (DataType dataType in _allDataTypes)
{
sb.Append(String.Format("\t\t<{0}>{2}</{0}>{1}", dataType.CamelCaseNotation, Environment.NewLine, dataType.GetDummyData()));
}
sb.Append(String.Format("\t</{0}>{1}", _singularCamelNotation, Environment.NewLine));
}
sb.Append(String.Format("</{0}>{1}", _pluralCamelNotation, Environment.NewLine));
return sb.ToString();
How can I do the same thing with LINQ, something like this:
PSEUDO-CODE:
var xdoc = new XDocument(
new XDeclaration("1.0", "utf-8", null),
for (int index = 0; index < 3; index++) {
new XElement(_pluralCamelNotation,
_allDataTypes.Select(datatype => new XElement(_singularCamelNotation,
new XElement(datatype.CamelCaseNotation, datatype.GetDummyData())
))
)
}
);