Is it possible to add literal XML data within a C# code file? I\'m currently using a multiline string literal but it gets messy as you can see. Any better way of doing this?
With reference to my comment, I couldn't recall where I saw this, but I finally found the XmlBuilder link.
In retrospect, it seems Linq to XML would be your best bet. It's cleaner, faster and more maintainable than concatenating XML strings:
XNamespace ns = "http://schemas.example.com/customui";
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "customUI",
new XElement(ns + "taskbar",
new XAttribute("id", "save"))
)
);
var stringWriter = new StringWriter();
doc.Save(stringWriter); //Write to StringWriter, preserving the declaration ()
var xmlString = stringWriter.ToString(); //Save as string
doc.Save(@"d:\out.xml"); //Save to file