运用XSD编写具有智能提示的XML文件(以SQL-MAP脚本为实例)

有了那一个XSD文件,在创造的Sql-Map配置文件的<sqlmap>
标签中,参加这么些XSD的采纳注脚,就能够见到智能提示的职能了。

 

<?xml version=”1.0″ encoding=”utf-8″ ?>
<xs:schema attributeFormDefault=”unqualified” elementFormDefault=”qualified” xmlns:xs=”http://www.w3.org/2001/XMLSchema"&gt;
    <xs:simpleType name=”enumCmdType” >
        <xs:restriction base =”xs:string”>
            <xs:enumeration value =”Text”></xs:enumeration>
            <xs:enumeration value =”StoredProcedure”></xs:enumeration>
Oracle,            <xs:enumeration value =”Table”></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=”enumResultClass” >
        <xs:restriction base =”xs:string”>
            <xs:enumeration value =”ValueType”></xs:enumeration>
            <xs:enumeration value =”DataSet”></xs:enumeration>
            <xs:enumeration value =”EntityObject”></xs:enumeration>
            <xs:enumeration value =”EntityList”></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=”enumScriptType” >
        <xs:restriction base =”xs:string”>
            <xs:enumeration value =”Access”></xs:enumeration>
            <xs:enumeration value =”SqlServer”></xs:enumeration>
            <xs:enumeration value =”SqlServerCe”></xs:enumeration>
            <xs:enumeration value =”Oracle”></xs:enumeration>
            <xs:enumeration value =”DB2″></xs:enumeration>
            <xs:enumeration value =”Sysbase”></xs:enumeration>
            <xs:enumeration value =”MySql”></xs:enumeration>
            <xs:enumeration value =”SQLite”></xs:enumeration>
            <xs:enumeration value =”PostgreSQL”></xs:enumeration>
            <xs:enumeration value =”UNKNOWN”></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name=”SqlMap”>
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs=”unbounded” name=”Script”>
                    <xs:complexType>
                         <xs:sequence>
                            <xs:element maxOccurs=”unbounded” name=”CommandClass”>
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:choice maxOccurs=”unbounded”>
                                            <xs:element maxOccurs=”unbounded” name=”Select”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”ResultClass” type=”enumResultClass” use=”optional”  default=”DataSet”/>
                                                            <xs:attribute name=”ResultMap” type=”xs:string” use=”optional” />
                                                            <xs:attribute name=”SqlPage” type=”xs:string” use=”optional” default=”False”/>
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                            <xs:element name=”Insert”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                            <xs:element name=”Update”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                            <xs:element name=”Delete”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                        </xs:choice>
                                    </xs:sequence>
                                    <xs:attribute name=”Name” type=”xs:string” use=”required” />
                                    <xs:attribute name=”Class” type=”xs:string” use=”required” />
                                    <xs:attribute name=”Interface” type=”xs:string” use=”optional” />
                                    <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name=”Type” type=”enumScriptType” use=”required”  />
                        <xs:attribute name=”Version” type=”xs:string” use=”optional” />
                        <xs:attribute name=”ConnectionString” type=”xs:string” use=”optional” />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name=”EmbedAssemblySource” type=”xs:string” use=”optional” />
        </xs:complexType>
    </xs:element>
</xs:schema>

PDF.NET代码生成器下载地址(包涵框架应用的完全示例),下载后请看里面包车型客车表达。

假如程序的数据库一点都不大概打开,请看看连接字符串是不是正确,或许将它附加到SQLSEEscortVETiggo实例上:

关于PDF.NET框架的事无巨细内容,请看自个儿的博客相关内容如故查看官网:http://www.pwmis.com/sqlmap

 

只顾文件中的simpleType
,它表示定义1个自定义的归纳类型,在XSD文件的节点中应用 type
属性来引用它即可。

 

xsi:noNamespaceSchemaLocation=”SqlMap.xsd”

connectionString=”Data
Source=.\SQLEXPRESS;AttachDbFilename=~\App_Data\PDFTest.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True”

 

 

下载达成后,将本文的SqlMap.xsd内容复制下来另存为文件即可,注意文件目录,假使该XSD文件跟SqlMap.config文件不在同二个,须求修改上面包车型大巴途径:

 

   
从上边的正儿八经看到,要手写2个SQL-MAP文件只怕相比复杂,尽管框架提供了SQL-MAP配置文件管理器,但它首要适用于新手使用,用起来作用不是很高,这几个时候就须要有2个足以只好提醒XML文件编写制定的东西了,这正是SqlMap.xsd,下边贴出该文件的风行完整内容:

   
SQL-MAP是PDF.NET(PWMIS数据开发框架)具有特色的开发技术,它能够将SQL语句映射成DAL代码,而且能够完毕无需IDAL和DalFactory自动切换数据库到此外一个数据库系统,比如SqlServer切换来Oralcle,有关SQL-MAP的正经请看那里,为啥要利用那种技能,请看“抽象SQL(参数化)查询
”。

 

        xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
        xsi:noNamespaceSchemaLocation=”SqlMap.xsd”>
<!– 在下边敲入尖括号,就可以出现当前节点区域内的应有编写的始末,来尝试吧 –>

方方面面XSD文件的编写要专注的也就如此多,编写起来照旧相比较简单的。

正文中定义了三个自定义类型enumCmdType,enumResultClass,enumScriptType
,而且是枚举类型(使用xs:enumeration 定义),那样在XML文件中就能够出现“下拉精选”的提醒意义了。

Oracle 1Oracle 2SqlMap.XSD

<SqlMap  

有了那些SqlMap.config文件,就可见采纳代码生成器自动生成DAL代码了。

在节点属性中,use=”required”
表示必须的性质,use=”optional”  表示可选的习性。

 

</SqlMap>

相关文章