This was created for the last assignment of Database Concepts & Programming and written in C#. The button "outputdb_btn_Click" is a button on the main page of a database application. When clicked it opens up the database in the default web browser as a html file with css styles applied. Currently only the account entity is exported.
The function also creates a matching XML file and a well formed XSD file.
// // //-----------------OUTPUT DATABASE AS XML, XSD & XSLT // // //get account details for each account and push them into a data set to //create XML and XSD files private void outputdb_btn_Click(object sender, EventArgs e) { var ds = new DataSet("Accounts"); var dt = ds.Tables.Add("Account"); dt.Columns.Add("ID", typeof(string)); dt.Columns.Add("username", typeof(string)); dt.Columns.Add("firstname", typeof(string)); dt.Columns.Add("surname", typeof(string)); dt.Columns.Add("phonenumber", typeof(string)); dt.Columns.Add("email", typeof(string)); dt.Columns.Add("password", typeof(string)); //create results list List<string>[] results = new List<string>[7]; //get results results = mySqlSrc.SelectAccount(); //count the rows int rows = results[0].Count; //loop through each row for (int i = 0; i < rows; ++i) { //[column][row] dt.Rows.Add(results[0][i], //account id results[1][i], //account username results[2][i], //account fname results[3][i], //accoutn sname results[4][i], //account phonenum results[5][i], //account email results[6][i]); //account password } //for use with stylesheets that use DOCTYPE //Prevents security error however this is a prototype and unfinished XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Parse; //Convert the data set into an XML file string xmlData = ds.GetXml(); string filepath = "dbxml.xml"; ds.WriteXml(filepath); //Convert the Data set into an XSD file string xmlSchema = ds.GetXmlSchema(); string filepath2 = "dbxmlschema.xsd"; ds.WriteXmlSchema(filepath2); //Transfrom either the xsd or xml into a styled webpage using the pre-defined stylesheet var myxslTrans = new XslCompiledTransform(); myxslTrans.Load("stylesheet.xsl"); myxslTrans.Transform(filepath, "result.html"); //launch webpage System.Diagnostics.Process.Start("result.html"); } } }