How To Use SQL XML ?

How To Use SQL XML ?

 

1.Program->Configure SQL XML Support in IIS

 

 

2. Create Virtual Directory

 

 

 

-2.1. Fill Virtual Name and Local Path

 

 

-2.2  Set Your Database Login User Name and Password

 

 

-2.3. Set SQL Server and Database

 

 

-2.4 Choice Setting Tab page -> Allow All

 

 

-2.5. Set Virtual Name.(Schema and Template in the Virtual Driver are have physics folder, Dbobject not have.)

 

 

 

-2.6 Click OK or Apply ->OK

 

3. Test SQL XML-> At the IE Address->

1. SQL In IE address

 

http://localhost/tr_xml?sql=SELECT+@@version+as+version+FOR+XML+RAW&root=root

 

 

2.XML File In IE address

 

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

<Menu xmlns:sql="urn:schemas-microsoft-com:xml-sql">

  <sql:query>

      SELECT  Menu_ID,Menu_Name,Url,Status

      FROM    TB_Menu

      FOR XML AUTO

    </sql:query>

</Menu>

 

 

3. Use Style Sheet Display

XML Name: Menu_List.xml

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

<?xml-stylesheet type="text/xsl" href="Menu_List.xsl"?>

<Menu xmlns:sql="urn:schemas-microsoft-com:xml-sql">

  <sql:query>

      SELECT  Menu_ID,Menu_Name,Url,Status

      FROM    TB_Menu

      FOR XML AUTO

    </sql:query>

</Menu>

 

 

XML Style Sheet Name: Menu_List.xsl

 

<?xml version='1.0' ?>         

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

    <xsl:template match="/">

        <html>

            <head>

                <title>Menu List</title>

                <base href="http://dg2pc0036/tr_xml/Template/" />

            </head>

            <body>

                <table border="0" cellPadding="1" cellSpacing="1"

                 width="100%"

                 style="COLOR:black;FONT-FAMILY:Arial;FONT-SIZE:12pt.;FONT-WEIGHT:500">

 

                <tr bgColor="#336699" align="center">

                    <TD><P ><STRONG><FONT color="white" size="2">Menu ID:</FONT></STRONG></P></TD>

                    <TD><P ><STRONG><FONT color="white" size="2">Menu Name:</FONT></STRONG></P></TD>

                    <TD><P ><STRONG><FONT color="white" size="2">Url:</FONT></STRONG></P></TD>

                    <TD><P ><STRONG><FONT color="white" size="2">Status:</FONT></STRONG></P></TD>

                </tr>

                               

                <xsl:for-each select="Menu/TB_Menu">

                    <tr style="COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 0.8em; FONT-WEIGHT: 500">

                        <td bgColor="#F0F0F0"><xsl:value-of select="@Menu_ID"/></td>

                        <td bgColor="#F0F0F0"><xsl:value-of select="@Menu_Name"/></td>

                        <td bgColor="#F0F0F0"><xsl:value-of select="@Url"/></td>

                        <td bgColor="#F0F0F0"><xsl:value-of select="@Status"/></td>

                    </tr>

                </xsl:for-each>

                </table>

            </body>

         </html>

    </xsl:template>

</xsl:stylesheet>

             

posted on 2009-03-17 14:23  封起De日子  阅读(101)  评论(0编辑  收藏  举报

导航