Saturday 2 May 2015

XML add root element

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
settings.OmitXmlDeclaration = true;

string strBody="<A>1</A><B>2</B>";
string strXML = "<Root>" + strBody + "</Root>";
XDocument xmlres = XDocument.Parse(strXML);
XmlWriter wrt = XmlWriter.Create("c:\\a.xml", settings);
xmlres.Save( wrt);
wrt.Close();