欢迎光临
我们一直在努力

C#分析数据库结构,使用XSL模板自动生成代码-.NET教程,C#语言

建站超值云服务器,限时71元/月

<html>

<head>

<title>分析数据库结构,自动生成代码</title>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

</head>

<frameset cols="237,767" rows="*">

<frame src="dbxml.aspx">

<frame name="code" src="about:blank">

</frameset>

</html>

########################### dbxml.aspx 文件内容,该文件没有c#代码文件 #############

<script language="c#" runat="server">

system.xml.xmldocument mycfgxml = new system.xml.xmldocument();

// 获得系统配置字符串

string getappconfig(string strkey)

{

system.xml.xmlelement cfgelement = mycfgxml.selectsinglenode ("//setting[@key=" + strkey + "]" )

as system.xml.xmlelement ;

if( cfgelement == null )

return "";

else

return cfgelement.innertext ;

}

// 判断字符串是否是空白字符串

bool isblankstring(string strtext )

{

if(strtext != null)

{

int icount;

for(icount=0;icount<strtext.length ;icount++)

{

if(system.char.iswhitespace ( strtext[icount])==false)

return false;

}

}

return true;

}

void page_load(object sender, eventargs e)

{

// 加载系统配置文件

mycfgxml.load(this.mappath(".") + "\\dbxmlcfg.xml");

string strtype = this.request["type"];

string strxsl = "main.xml";

if(strtype == null)

strtype = "querytable";

system.xml.xmldocument mydoc = new system.xml.xmldocument();

mydoc.loadxml("<dbxml />");

string strconnection = getappconfig("conndbxml");

system.text.encoding myencode = system.text.encoding.getencoding(936);

if(isblankstring(strconnection)==false)

{

using(system.data.oledb.oledbconnection myconn = new system.data.oledb.oledbconnection(strconnection))

{

myconn.open();

if(myconn.state == system.data.connectionstate.open )

{

string strsql = getappconfig(strtype + "_" + myconn.provider);

if(isblankstring(strsql)==false)

{

using(system.data.oledb.oledbcommand mycmd = myconn.createcommand())

{

string strtablename = null;

if(strtype.equals("queryfield"))

{

// 修正sql语句

string strtablelist = this.request.form["tablelist"];

string []strtables = strtablelist.split(",".tochararray());

strxsl = system.web.httputility.urlpathencode(this.request.form["template"] ) + ".xml";

strtablelist = null;

for(int icount = 0 ; icount < strtables.length ; icount ++ )

{

if(isblankstring(strtables[icount])==false)

{

if(strtablelist == null)

strtablelist = "" + strtables[icount] + "";

else

strtablelist = strtablelist + "," + strtables[icount] + "";

}

}

strsql = strsql.replace("#tablelist", strtablelist);

mycmd.commandtext = strsql ;

string strlasttablename = null;

string strfieldname = null;

system.xml.xmlelement tableelement = null;

system.data.oledb.oledbdatareader myreader = mycmd.executereader();

while(myreader.read())

{

strtablename = myreader[0].tostring().toupper();

if(strtablename.equals(strlasttablename)==false)

{

// 填充表说明元素

strlasttablename = strtablename ;

tableelement = mydoc.createelement("table");

tableelement.setattribute("tablename", strtablename);

mydoc.documentelement.appendchild(tableelement);

}

// 填充字段说明元素

system.xml.xmlelement fieldelement = mydoc.createelement("field");

fieldelement.setattribute("fieldname", myreader[1].tostring());

fieldelement.setattribute("fieldtype", myreader[2].tostring());

fieldelement.setattribute("fieldwidth", myreader[3].tostring());

fieldelement.setattribute("isstring", (myreader[2].tostring().toupper().indexof("char")>=0?"1":"0"));

strfieldname = myreader[1].tostring();

int ilen = myencode.getbytecount(strfieldname);

if(ilen < 20)

fieldelement.setattribute("fixname", strfieldname + new string( , 20 – ilen));

tableelement.appendchild(fieldelement);

}

myreader.close();

}

else

{

// 填充模板列表

string [] strfilenames = system.io.directory.getfiles(this.server.mappath("."),"temp_*.xml");

for(int icount = 0 ; icount < strfilenames.length ; icount ++ )

{

system.xml.xmlelement tempxml = mydoc.createelement("template");

tempxml.setattribute("key",system.io.path.getfilenamewithoutextension(strfilenames[icount]));

mydoc.documentelement.appendchild(tempxml);

}

// 填充表名列表

mycmd.commandtext = strsql ;

system.data.oledb.oledbdatareader myreader = mycmd.executereader();

system.xml.xmlelement tableelement = null;

while(myreader.read())

{

tableelement = mydoc.createelement("table");

mydoc.documentelement.appendchild(tableelement);

strtablename = myreader[0].tostring();

tableelement.setattribute("name", strtablename );

tableelement.setattribute("count", myreader[1].tostring());

int ilen = myencode.getbytecount(strtablename);

if(ilen < 20 )

tableelement.setattribute("fixname",strtablename + new string( , 20 – ilen));

}

myreader.close();

}

}

}

}

myconn.close();

}

}

// 输出文档

this.response.contenttype = "text/xml";

this.response.contentencoding = myencode ;

this.response.write("<?xml version=\"1.0\" encoding=\"gb2312\" ?>");

this.response.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + strxsl + "\"?>");

this.response.write(mydoc.documentelement.outerxml);

}

</script>

文件 dbxmlcfg.xml内容

——————————————————————————–

<?xml version="1.0" encoding="utf-8" ?>

<application>

<settings>

<setting key="conn">provider=sqloledb.1;password=123456;persist security info=true;user id=cpr;initial catalog=htioa;data source=192.168.0.124</setting>

<setting key="conndbxml">provider=sqloledb.1;integrated security=sspi;persist security info=false;initial catalog=issuevision;data source=(local)</setting>

<!–

定义查询表结构使用的sql语句,

queryfield_驱动程序名称 定义了查询指定表的字段定义的sql语句,该语句带有一个参数

querytable_驱动程序名称 定义了查询所有表名及其字段个数的sql语句,该语句没有参数

目前定义了 oracle和ms sql server 的sql语句

–>

<setting key="queryfield_oraoledb.oracle.1">select tname ,cname ,coltype ,width from col where tname in (#tablelist) order by tname,cname</setting>

<setting key="querytable_oraoledb.oracle.1">select tname ,count(*) from col group by tname order by tname </setting>

<setting key="queryfield_sqloledb.1"><![cdata[select sysobjects.name ,syscolumns.name ,systypes.name ,syscolumns.length from syscolumns,sysobjects,systypes where syscolumns.id=sysobjects.id and syscolumns.xtype=systypes.xtype and sysobjects.type=u and systypes.name <>_default_ and systypes.name<>sysname and sysobjects.name in (#tablelist) order by sysobjects.name,syscolumns.name]]></setting>

<setting key="querytable_sqloledb.1"><![cdata[select sysobjects.name ,count(*) from syscolumns,sysobjects,systypes where syscolumns.id=sysobjects.id and syscolumns.xtype=systypes.xtype and sysobjects.type=u and systypes.name <>_default_ and systypes.name<>sysname group by sysobjects.name order by sysobjects.name]]></setting>

</settings>

</application>

####################### main.xml ##################################

<?xml version="1.0" encoding="gb2312" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/*">

<html>

<head>

<title></title>

<style>

select2{ font-family: "宋体"; font-size: 12px}

body{ font-family: "宋体"; font-size: 12px}

table{ width:100%; border-collapse:collapse;

border: 1px #cc0066 solid; font-family: "宋体";

font-size: 12px}

.tablehead{background-color:#ccccff}

td{ border: 1px #cc0066 solid} </style>

</head>

<body leftmargin=1 rightmargin=1 topmargin="1">

<form name="frm" target="code" method="post" action="dbxml.aspx?type=queryfield">

模板<select name="template">

<xsl:for-each select="template">

<option>

<xsl:attribute name="value">

<xsl:value-of select="@key" />

</xsl:attribute>

<xsl:value-of select="@key" />

</option>

</xsl:for-each>

</select>

<input type="submit" value="提交" />

<table>

<tr class="tablehead">

<td nowrap="1">选择</td>

<td nowrap="1">表名</td>

<td nowrap="1">字段个数</td>

</tr>

<xsl:for-each select="table">

<tr>

<td nowrap="1">

<input type="checkbox" name="tablelist" style="width:13;height:13">

<xsl:attribute name="value">

<xsl:value-of select="@name" />

</xsl:attribute>

</input>

</td>

<td>

<xsl:value-of select="@name" />

</td>

<td>

<xsl:value-of select="@count" />

</td>

</tr>

</xsl:for-each>

</table>

</form>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

############################### temp_csharp.xml 内容 ############################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">

<html>

<head></head>

<body>

<xsl:for-each select="*/table">

<br />————– 文件名 <xsl:value-of select="@tablename" />.cs —————————–

<pre style=" background-color:gainsboro">

//—————————————————————————–

<xsl:text disable-output-escaping="yes">

/// <summary></xsl:text>

/// 数据库表 <xsl:value-of select="@tablename" /> 操作对象

/// 编制: 代码生成器

/// 时间:

<xsl:text disable-output-escaping="yes"> /// </summary></xsl:text>

public class struct<xsl:value-of select="@tablename" /> : commonstruct

{ private const string c_tablename ="<xsl:value-of select="@tablename" />";

// 定义数据库字段变量 ////////////////////////////////////////////////////////////////

<xsl:for-each select="*">

<xsl:variable name="csharptype">

<xsl:choose>

<xsl:when test="@isstring=1">string </xsl:when>

<xsl:when test="boolean(true)">int </xsl:when>

</xsl:choose>

</xsl:variable>

<xsl:variable name="lowfieldname">

<xsl:value-of select="translate(@fieldname,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />

</xsl:variable>

private <xsl:value-of select="$csharptype" /> m_<xsl:value-of select="@fixname" /> ; // 字段 <xsl:value-of select="@cname" />

</xsl:for-each>

// 定义属性 ///////////////////////////////////////////////////////////

<xsl:for-each select="*">

<xsl:variable name="csharptype">

<xsl:choose>

<xsl:when test="@isstring=1">string </xsl:when>

<xsl:when test="boolean(true)">int </xsl:when>

</xsl:choose>

</xsl:variable>

/// <xsl:text disable-output-escaping="yes">&lt;summary&gt;</xsl:text>

/// 设置/返回数据库字段属性 <xsl:value-of select="@cname" />

/// <xsl:text disable-output-escaping="yes">&lt;/summary&gt;</xsl:text>

/// <xsl:text disable-output-escaping="yes">&lt;returns&gt;</xsl:text><xsl:value-of select="@cname" /><xsl:text disable-output-escaping="yes"> &lt;/returns&gt;</xsl:text>

public <xsl:value-of select="$csharptype" /> m<xsl:value-of select="@fieldname" />

{

get{ return m_<xsl:value-of select="@fieldname" /> ;}

set{ m_<xsl:value-of select="@fieldname" /> = value ;}

}

</xsl:for-each>

new public static string gettablename()

{return c_tablename ;}

new public static string getselectsql()

{

return "select <xsl:for-each select="*">

<xsl:value-of select="normalize-space(@fieldname)" />

<xsl:if test="position() != last()">,</xsl:if>

</xsl:for-each> from " + c_tablename ;

}

new public static string gettypename()

{

return "<xsl:value-of select="translate(@tablename,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />";

}

new public static string searchkey(string strkey)

{

return getselectsql() + " where seq =" + strkey ;

}

public override bool setcommandparams( system.data.oledb.oledbcommand mycmd,bool setvalues )

{

if(mycmd!= null)

{

mycmd.parameters.clear ();

<xsl:for-each select="*">

mycmd.parameters.add("<xsl:value-of select="normalize-space(@fieldname)" />",system.data.oledb.oledbtype.<xsl:if test="@isstring=1">varwchar</xsl:if><xsl:if test="@isstring=0">integer</xsl:if>);</xsl:for-each>

if(setvalues)

{

<xsl:for-each select="*">

mycmd.parameters[<xsl:value-of select="position()-1" />].value = m_<xsl:value-of select="@fieldname" /> ; // 字段 <xsl:value-of select="@cname" />

</xsl:for-each>

}

return true;

}

return false;

}

public override bool setinsertcommand( system.data.oledb.oledbcommand mycmd)

{

if(mycmd != null)

{

mycmd.commandtext ="insert into " + c_tablename

+ " ( <xsl:for-each select="*">[<xsl:value-of select="normalize-space(@fieldname)" />]<xsl:if test="position() != last()">,</xsl:if>

</xsl:for-each>) values (<xsl:for-each select="*">?<xsl:if test="position() != last()">,</xsl:if>

</xsl:for-each>)";

return this.setcommandparams(mycmd,true);

}

return false;

}

public override bool setupdatecommand(system.data.oledb.oledbcommand mycmd)

{

if(mycmd != null)

{

mycmd.commandtext ="update " + c_tablename

+ " set <xsl:for-each select="*">[<xsl:value-of select="normalize-space(@fieldname)" />]=? <xsl:if test="position() != last()">,</xsl:if></xsl:for-each> where seq=" + m_seq ;

return this.setcommandparams(mycmd,true);

}

return false;

}

public override bool selectrs(system.data.oledb.oledbdatareader myreader)

{

try

{

if(myreader != null)

{

if (myreader.fieldcount==5)

{

<xsl:for-each select="*">

m_<xsl:value-of select="@fixname" /> = convert.to<xsl:if test="@isstring=1">string</xsl:if><xsl:if test="@isstring=0">int32</xsl:if>(myreader[<xsl:value-of select="position()-1" />]);</xsl:for-each>

return true;

}

}

}

catch

{}

return false;

}

public override bool toxml(system.xml.xmlelement myelement)

{

if(myelement != null)

{

<xsl:for-each select="*">

myelement.setattribute("<xsl:value-of select="translate(@fieldname,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />",m_<xsl:value-of select="@fieldname" /><xsl:if test="@isstring=0">.tostring()</xsl:if>);</xsl:for-each>

return true;

}

return false;

}

public override bool fromxml(system.xml.xmlelement myelement)

{

try

{

if(myelement != null)

{

<xsl:for-each select="*">

m_<xsl:value-of select="@fixname" /> = <xsl:if test="@isstring=0">convert.toint32(</xsl:if>myelement.getattribute("<xsl:value-of select="translate(@fieldname,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />")<xsl:if test="@isstring=0">)</xsl:if>;</xsl:for-each>

return true;

}

}

catch

{}

return false;

}

}// 数据库操作类 struct<xsl:value-of select="@tablename" /> 定义结束

</pre>

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

########################## temp_html代码.xml #####################################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/*">

<html>

<head>

<style>

body{ font-family: "宋体"; font-size: 12px}

table { width:100%; border-collapse:collapse;

border: 1px #cc0066 solid; font-family: "宋体";

font-size: 12px}

.tablehead{background-color:#ccccff}

td{ border: 1px #cc0066 solid}

</style>

</head>

<body>

<xsl:for-each select="table">

数据表 <b><xsl:value-of select="translate(@tablename,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" /></b> 结构

共 <xsl:value-of select="count(*)" /> 个字段

<br />

<table >

<tr class="tablehead">

<td>字段名</td>

<td>类型</td>

<td>长度</td>

</tr>

<xsl:for-each select="*">

<tr>

<td>

<xsl:value-of select="@fieldname" />

</td>

<td>

<xsl:value-of select="@fieldtype" />

</td>

<td>

<xsl:value-of select="@fieldwidth" />

</td>

</tr>

</xsl:for-each>

</table>

<p /><hr />

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

################################ temp_java_struct.xml #######################################################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">

<html><head></head><body>

<xsl:for-each select="*/table">

<br />————– 文件名 <xsl:value-of select="@tablename" />.java —————————–

<pre style=" background-color:gainsboro">

package com.haitai.emr.struct;

import java.sql.*;

import java.io.*;

/** <xsl:value-of select="@cname" />

* @author 代码生成器 */

public class <xsl:value-of select="@tablename" /> implements serializable

{ // 定义数据库字段变量 ////////////////////////////////////////////////////////////////

<xsl:for-each select="*">

<xsl:variable name="javatype">

<xsl:choose>

<xsl:when test="@isstring=1">string </xsl:when>

<xsl:when test="boolean(true)" >int </xsl:when>

</xsl:choose>

</xsl:variable>

<xsl:variable name="lowfieldname">

<xsl:value-of select="translate(@fixname,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />

</xsl:variable>

private <xsl:value-of select="$javatype" /> <xsl:text disable-output-escaping="yes"></xsl:text><xsl:value-of select="$lowfieldname" /> ; // 字段 <xsl:value-of select="@cname" />

</xsl:for-each>

public static final string select =

"select <xsl:for-each select="*">

<xsl:value-of select="normalize-space(@fieldname)" />

<xsl:if test="position() != last()">,</xsl:if>

</xsl:for-each> from <xsl:value-of select="@tablename" />";

/** @param conn

* @exception sqlexception */

public java.sql.preparedstatement makeinsst (java.sql.connection conn) throws sqlexception{

preparedstatement pst=conn.preparestatement("insert into <xsl:value-of select="@tablename" />(<xsl:for-each select="*">

<xsl:value-of select="normalize-space(@fieldname)" />

<xsl:if test="position() != last()">,</xsl:if>

</xsl:for-each>)"

+"values(<xsl:for-each select="*">?<xsl:if test="position() != last()">,</xsl:if></xsl:for-each>)");

int index=0;

<xsl:for-each select="*">

pst.setstring(++index,this.get<xsl:value-of select="@fieldname" />()); // <xsl:value-of select="@cname" />

</xsl:for-each>

return pst;

}

/** @param conn

* @exception sqlexception */

public java.sql.preparedstatement makeupdst (java.sql.connection conn) throws sqlexception{

// todo : implement

preparedstatement pst=conn.preparestatement("update <xsl:value-of select="@tablename" /> set <xsl:for-each select="*"><xsl:value-of select="normalize-space(@fieldname)" /> =? <xsl:if test="position() != last()">,</xsl:if></xsl:for-each>)"

+"where 数据表关键字段名=?");

int index=0;

<xsl:for-each select="*">

pst.setstring(++index,this.get<xsl:value-of select="@fieldname" />()); // <xsl:value-of select="@cname" />

</xsl:for-each>

//关键字

pst.setstring(++index,this.get数据表关键字段名());//数据表关键字段说明

return pst;

}

public string tostring (){

// todo : implement

return <xsl:for-each select="*">"<xsl:if test="position() != 1">,</xsl:if><xsl:value-of select="normalize-space(@fieldname)" />="+ <xsl:value-of select="@lowfieldname" /><xsl:if test="position() != last()"> + </xsl:if> </xsl:for-each>;

}

// 读取和修改数据的接口

<xsl:for-each select="*">

<xsl:variable name="javatype">

<xsl:choose>

<xsl:when test="@isstring=1">string</xsl:when>

<xsl:when test="boolean(true)">int</xsl:when>

</xsl:choose>

</xsl:variable>

<xsl:variable name="lowfieldname">

<xsl:value-of select="translate(@fieldname,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />

</xsl:variable>

public <xsl:value-of select="$javatype" /> get<xsl:value-of select="@fieldname" />(){

return <xsl:value-of select="normalize-space($lowfieldname)" /> ;

}

//@param <xsl:value-of select="@cname" />

public void set<xsl:value-of select="@fieldname" />(<xsl:value-of select="@javatype" /> value){

<xsl:value-of select="normalize-space($lowfieldname)" /> = value ;

}

</xsl:for-each>

} // 类 <xsl:value-of select="@tablename" /> 定义结束

</pre>

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

######################################## temp_vb.xml ############################################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">

<html>

<head></head>

<body>

<xsl:for-each select="*/table">

<br />————– 文件名 <xsl:value-of select="@tablename" />.cls —————————–

<pre style=" background-color:gainsboro">

******************************************************************************

**

** 数据表 <xsl:value-of select="@cname" />[ <xsl:value-of select="@tablename" /> ]操作的对象

**

** 编制:代码生成器

** 时间:

**

******************************************************************************

** 定义和数据库字段对应的变量 *************************************************************

private const c_tablename as string = "<xsl:value-of select="@tablename" />" ** 数据表名称

<xsl:for-each select="*">

<xsl:variable name="vbtype">

<xsl:choose>

<xsl:when test="@isstring=1">string </xsl:when>

<xsl:when test="boolean(true)" >integer </xsl:when>

</xsl:choose>

</xsl:variable>

<xsl:variable name="lowfieldname">

<xsl:value-of select="translate(@fieldname,abcdefghijklmnopqrstuvwxyz,abcdefghijklmnopqrstuvwxyz)" />

</xsl:variable>

private m_<xsl:value-of select="@fixname" /> as <xsl:value-of select="$vbtype" /> ** 字段 <xsl:value-of select="@cname" />

</xsl:for-each>

** 定义数据库字段属性接口 ***************************************************************

public property get tablename() as string

tablename = c_tablename

end property

<xsl:for-each select="*">

<xsl:variable name="vbtype">

<xsl:choose>

<xsl:when test="@isstring=1">string </xsl:when>

<xsl:when test="boolean(true)" >integer </xsl:when>

</xsl:choose>

</xsl:variable>

** 数据库字段 <xsl:value-of select="@cname" />

public property get m<xsl:value-of select="@fieldname" />() as <xsl:value-of select="$vbtype" />

m<xsl:value-of select="@fieldname" /> = m_<xsl:value-of select="@fieldname" />

end property

public property let m<xsl:value-of select="@fieldname" />(byval value as <xsl:value-of select="$vbtype" />)

m_<xsl:value-of select="@fieldname" /> = m<xsl:value-of select="@fieldname" />

end property

</xsl:for-each>

** 获得查询所有数据使用的sql语句 **

public function getbasesql() as string

getbasesql ="select <xsl:for-each select="*">

<xsl:value-of select="@fieldname" />

<xsl:if test="position() != last()">,</xsl:if>

</xsl:for-each> from " <xsl:text disable-output-escaping="yes">&</xsl:text> c_tablename

end function

** 定义从数据库记录集获得数据的方法 **

public function selectrs(byval rs as adodb.recordset) as boolean

on error goto selecterr

selectrs = false

<xsl:for-each select="*">

m_<xsl:value-of select="@fixname" /> = rs.fields(<xsl:value-of select="position()-1" />).value ** 字段 <xsl:value-of select="@cname" />

</xsl:for-each>

selectrs = true

exit function

selecterr:

selectrs = false

end function

</pre>

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

####################### temp_表说明文档.xml ##################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:template match="/">

<html>

<head></head>

<body>

<xsl:for-each select="*/table">

————-表 <xsl:value-of select="@tablename" /> 的说明文档 <xsl:value-of select="count(*)" />个字段

<br /><pre style="word-wrap:break-word;background-color:gainsboro">

<xsl:for-each select="*"><xsl:value-of select="@fixname" /><xsl:text disable-output-escaping="yes"> </xsl:text><xsl:value-of select="@fieldtype" />

<xsl:if test="@isstring=1">(<xsl:value-of select="@fieldwidth" />)</xsl:if> .

<xsl:text disable-output-escaping="yes"></xsl:text>

</xsl:for-each>

</pre>

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

####################### temp_创建表的sql语句.xml ##################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:template match="/">

<html>

<head></head>

<body>

<xsl:for-each select="*/table">

————-创建表 <xsl:value-of select="@tablename" /> 的sql语句 <xsl:value-of select="count(*)" />个字段

<br /><pre style="word-wrap:break-word;background-color:gainsboro">

create table <xsl:value-of select="@tablename" />(

<xsl:for-each select="*">

<xsl:text disable-output-escaping="yes"></xsl:text>

<xsl:value-of select="@fixname" />

<xsl:value-of select="@fieldtype" />

<xsl:if test="@isstring=1">(<xsl:value-of select="@fieldwidth" />)</xsl:if>

<xsl:if test="position() != last()"> ,

</xsl:if>

</xsl:for-each>

)

</pre>

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

####################### temp_选择表使用的sql语句.xml ##################################

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:template match="/">

<html>

<head></head>

<body>

<xsl:for-each select="*/table">

————-选择表 <xsl:value-of select="@tablename" /> 的sql语句 <xsl:value-of select="count(*)" />个字段

<br /><pre style="word-wrap:break-word;background-color:gainsboro">

select <xsl:for-each select="*">

<xsl:text disable-output-escaping="yes"></xsl:text>

<xsl:value-of select="normalize-space(@fieldname)" />

<xsl:if test="position() != last()"> , </xsl:if>

</xsl:for-each>

from <xsl:value-of select="@tablename" /></pre>

</xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » C#分析数据库结构,使用XSL模板自动生成代码-.NET教程,C#语言
分享到: 更多 (0)