I like to create xml using the following formatting:
XDocument xml = new XDocument(
new XElement("Root",
new XElement("A",
new XAttribute("X", xValue),
new XAttribute("Y", yValue)),
new XElement("B",
new XAttribute("Z", zValue)),
new XElement("C")));
It seems easy to read and kinda flows like a tabbed XML document (in my opinion). StyleCop is very unhappy with the formatting though. I get a lot of these errors:
SA1116: If the method parameters are on separate lines, the first parameter must begin on the line beneath the name of the method.
SA1118: The parameter spans multiple lines. If the parameter is short, place the entire parameter on a single line. Otherwise, save the contents of the parameter in a temporary variable and pass the temporary variable as a parameter.
What can i do to keep StyleCop happy and the code readable? I know i can disable the StyleCop rules, but the team would like to keep those rules for all the non XML creation code. I can selectively suppress the rule in every method that creates XML in this way, but that seems like a pain and gets to be ugly. Any suggestions?