// <Summary> // This method is used to export a DataRow object to xml. // </Summary> public string ExportDataRow(DataRow dataRow, int indent = 0) { // initial value string dataRowXml = ""; // locals string indentString = TextHelper.Indent(indent); string indentString2 = TextHelper.Indent(indent + 2); // If the dataRow object exists if (NullHelper.Exists(dataRow)) { // Create a StringBuilder StringBuilder sb = new StringBuilder(); // Append the indentString sb.Append(indentString); // Write the open dataRow node sb.Append("<DataRow>" + Environment.NewLine); // Write out each property // Write out the value for Changes sb.Append(indentString2); sb.Append("<Changes>" + dataRow.Changes + "</Changes>" + Environment.NewLine); // Write out the value for Delete sb.Append(indentString2); sb.Append("<Delete>" + dataRow.Delete + "</Delete>" + Environment.NewLine); // Write out the value for Fields // Create the FieldsWriter FieldsWriter fieldsWriter = new FieldsWriter(); // Export the Fields collection to xml string dataFieldXml = fieldsWriter.ExportList(dataRow.Fields, indent + 2); sb.Append(dataFieldXml); sb.Append(Environment.NewLine); // Write out the value for Index sb.Append(indentString2); sb.Append("<Index>" + dataRow.Index + "</Index>" + Environment.NewLine); // Write out the value for ParentTable sb.Append(indentString2); sb.Append("<ParentTable>" + dataRow.ParentTable + "</ParentTable>" + Environment.NewLine); // Append the indentString sb.Append(indentString); // Write out the close dataRow node sb.Append("</DataRow>" + Environment.NewLine); // set the return value dataRowXml = sb.ToString(); } // return value return(dataRowXml); }
// <Summary> // This method is used to export a DataTable object to xml. // </Summary> public string ExportDataTable(DataTable dataTable, int indent = 0) { // initial value string dataTableXml = ""; // locals string indentString = TextHelper.Indent(indent); string indentString2 = TextHelper.Indent(indent + 2); // If the dataTable object exists if (NullHelper.Exists(dataTable)) { // Create a StringBuilder StringBuilder sb = new StringBuilder(); // Append the indentString sb.Append(indentString); // Write the open dataTable node sb.Append("<DataTable>" + Environment.NewLine); // Write out each property // (Manually added Name to the top so you do not have to scroll down to find the name // Write out the value for Name sb.Append(indentString2); sb.Append("<Name>" + dataTable.Name + "</Name>" + Environment.NewLine); // Write out the value for CheckConstraints // Create the CheckConstraintsWriter CheckConstraintsWriter checkConstraintsWriter = new CheckConstraintsWriter(); // Export the CheckConstraints collection to xml string checkConstraintXml = checkConstraintsWriter.ExportList(dataTable.CheckConstraints, indent + 2); sb.Append(checkConstraintXml); sb.Append(Environment.NewLine); // Write out the value for Fields // Create the FieldsWriter FieldsWriter fieldsWriter = new FieldsWriter(); // Export the Fields collection to xml string dataFieldXml = fieldsWriter.ExportList(dataTable.Fields, indent + 2); sb.Append(dataFieldXml); sb.Append(Environment.NewLine); // Write out the value for ForeignKeys // Create the foreignKeyWriter ForeignKeysWriter foreignKeyWriter = new ForeignKeysWriter(); // Write out the value for ForeignKeys string foreignKeyXml = foreignKeyWriter.ExportList(dataTable.ForeignKeys, indent + 2); sb.Append(foreignKeyXml); sb.Append(Environment.NewLine); // Write out the value for Indexes // Create the IndexesWriter IndexesWriter indexesWriter = new IndexesWriter(); // Export the Indexes collection to xml string dataIndexXml = indexesWriter.ExportList(dataTable.Indexes, indent + 2); sb.Append(dataIndexXml); sb.Append(Environment.NewLine); // Write out the value for IsView sb.Append(indentString2); sb.Append("<IsView>" + dataTable.IsView + "</IsView>" + Environment.NewLine); // Write out the value for SchemaName sb.Append(indentString2); sb.Append("<SchemaName>" + dataTable.SchemaName + "</SchemaName>" + Environment.NewLine); // Append the indentString sb.Append(indentString); // Write out the close dataTable node sb.Append("</DataTable>" + Environment.NewLine); // set the return value dataTableXml = sb.ToString(); } // return value return(dataTableXml); }