MS SQL Server
  Home arrow MS SQL Server arrow Page 5 - XML and the SQL 2000 Server, Part 2
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

XML and the SQL 2000 Server, Part 2
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 8
    2005-03-14

    Table of Contents:
  • XML and the SQL 2000 Server, Part 2
  • Mapping Virtual Objects
  • Using Select Queries in URL
  • Considerations When Sending Queries to a URL
  • What are template queries?
  • Stored procedures with templates
  • Display the HTML file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    XML and the SQL 2000 Server, Part 2 - What are template queries?


    (Page 5 of 7 )

    First of all, a template is a well formed XML document. The document contains one or more SQL or Xpath queries; SQL statements such as select, insert, delete, and update; stored procedures; xpath queries; and xsl. The vulnerabilities of URL queries are avoided because the SQL is hidden in a file kept in the directory of type template.

    The generic format of a template syntax which has the extension xml is shown here:

    <root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:xsl='xslFilename'>
    <sql:header>
    <sql:param>    ...    </sql:param:>
    <sql:param>    ...    </sql:param:>
    <sql:param>    ...    </sql:param:>
    .
    .
    </sql:header>
    <sql:query>
    SQL Statements
    </sql:query>
    <sql:xpath-query mapping-schema="SchemaFileName.xml">
    XPath Query
    </sql:xpath>
    </root>
    

    It was seen earlier that the for xml clause returns a XML Fragment rather than a well-formed XML document. The first line esablishes a <root> top level element for the XML document besides declaring the namespace. The sql:xsl='xslFilename' refers to an applicable style sheet for formatting the document. The path for this file can be relative, or absolute.

    The <sql:header> tag is optional and when used with queries requiring parameters, single parameter per line of <sql:param> ... </sql:param:> are inserted here. Multiple parameters may be specified. Rules of well formed document requires correct closing tags.

    The <sql:query> tag is where the SQL statements are inserted. It is permissible to place multiple SQL statements here. Each statement is considered as a different transaction. Stored procedures may also be placed here.

    <sql:xpath-query mapping-schema="SchemaFileName.xml"> specifies the XPath query. The XPath query is always executed against the annotated XDR schema. This attribute must always be present for the XPath query. This will be considered in a future article. For now the focus is on queries.

    Once the template file is created, it should be placed in, or uploaded to, the Template directory of the server's local file system, so that it can be processed by the server. A couple of examples will be considered in the following section to make the usage of template files clearer.

    Accessing data with a template file

    Although a generic syntax was described, it is not necessary to have all the elements to run a template query. A simple example of a template file is:

    Now this file (named NCity.xml) is placed in the Template directory as mentioned earlier. The template file can be accessed by sending the following string to the URL:

    http://xphtek/PubsVirtual/Templates/NCity.xml to yield the following result:

    More MS SQL Server Articles
    More By Jayaram Krishnaswamy


     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT