I am trying to figure out what the best method is for writing an XML Document. Below is a simple example of what I am trying to create off of data I am pulling from our ERP syst
I had to create following XML document having some part of it parametrized.
And here's my code that does this with single LINQ statement.
Make a note that creating XML document above using LINQ and saving it to XML file preserves the XML document formatting and keeps line-breaks and carriage-returns that makes the document properly tabified.
public string CreateOTAXmlFile(string Username, string Password)
{
var ota = new XDocument(
new XElement("wap-provisioningdoc",
new XElement("characteristic", new XAttribute("type", "BOOTSTRAP"),
new XElement("parm", new XAttribute("name", "NAME"), new XAttribute("value", "SYNCSETTINGS"))
),
new XElement("characteristic", new XAttribute("type", "APPLICATION"),
new XElement("parm", new XAttribute("name", "APPID"), new XAttribute("value", "w5")),
new XElement("parm", new XAttribute("name", "TO-NAPID"), new XAttribute("value", "INTERNET")),
new XElement("parm", new XAttribute("name", "NAME"), new XAttribute("value", "SYNCSETTINGS")),
new XElement("parm", new XAttribute("name", "ADDR"), new XAttribute("value", "http://syncserver/sync")),
new XElement("characteristic", new XAttribute("type", "RESOURCE"),
new XElement("parm", new XAttribute("name", "URI"), new XAttribute("value", "pb")),
new XElement("parm", new XAttribute("name", "NAME"), new XAttribute("value", "Contacts DB")),
new XElement("parm", new XAttribute("name", "AACCEPT"), new XAttribute("value", "text/x-vcard"))
),
new XElement("characteristic", new XAttribute("type", "RESOURCE"),
new XElement("parm", new XAttribute("name", "URI"), new XAttribute("value", "cal")),
new XElement("parm", new XAttribute("name", "NAME"), new XAttribute("value", "Calendar DB")),
new XElement("parm", new XAttribute("name", "AACCEPT"), new XAttribute("value", "text/x-vcalendar"))
),
new XElement("characteristic", new XAttribute("type", "RESOURCE"),
new XElement("parm", new XAttribute("name", "URI"), new XAttribute("value", "notes")),
new XElement("parm", new XAttribute("name", "NAME"), new XAttribute("value", "Notes DB")),
new XElement("parm", new XAttribute("name", "AACCEPT"), new XAttribute("value", "text/plain"))
),
new XElement("characteristic", new XAttribute("type", "APPAUTH"),
new XElement("parm", new XAttribute("name", "AAUTHNAME"), new XAttribute("value", Username)),
new XElement("parm", new XAttribute("name", "AAUTHSECRET"), new XAttribute("value", Password))
)
)
)
);
ota.Save(Server.MapPath("~/OTA/") + Username + ".xml");
return (ota.ToString());
}