You must Sign In to post a response.
  • Category: XML

    How to generate table script from XSD files in .net ?


    Are you looking for a way to generate table script from XSD files in .net ? then read this thread to know more about it



    Hi All,
    I just want to try to do this in .net code . Code will return table scripts taking input as XSD file info. This is possible by using XML spy , but whether it can be done using .net ?
    Thanks
    R R Mishra
  • #729500
    Hi,

    Check the below links

    http://www.codeproject.com/Articles/76814/Generate-SQL-Database-Schema-from-XML-Part-1-File

    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/fca0892d-78d3-4469-a4b0-f21eede688f5/can-i-create-a-database-schema-from-a-dataset-andor-xsd-file

    http://stackoverflow.com/questions/11656324/how-can-i-generate-create-table-script-from-code

    Thanks & Regards,
    Mahesh Durgam

  • #729876
    You can use this code snippet for generate Table Script from XSD

    <#PrepareToRender(); #>

    <#

    foreach (DataTable Data1 in dset.Tables) {

    tableName= data1.ToString();

    #>

    CREATE TABLE <#= YourtableName #>

    (

    <#

    PushIndent(" ");
    foreach (DataColumn dsoc in data1.Columns) {
    WriteLine( dsoc.ToString() + " " + MapToSqlType(dsoc.DataType.Name) + ",");
    }
    PopIndent();
    #>
    )
    <#

    }

    #>

    <#+

    DataSet dset;
    string tableName;
    void PrepareToRender()
    {
    dset = new System.Data.DataSet();
    dset.ReadXmlSchema("Metadata.xsd");
    }
    string MapToSqlType(string clrType)
    {
    switch(clrType)
    {
    case "String":
    return "Varchar(50)";
    case "Int32":
    return "int";
    default:
    return clrType;

    }
    }
    #>


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.