Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

SQL Server
SQL Server Automating Administration
SQL Server Full Text Searching
SQL Server Installing
SQL Server Selecting XML Data
SQL Server XSL Stylesheets
SQL Server Stored Procedures
SQL Server XDR Schemes
SQL Server Indexed Views
SQL Server Introduction
SQL Server Data Statements
SQL Server SELECT Statement
SQL Server Modification Statements
SQL ServerTransaction Statements
SQL Server Schema Statements
SQL Server XML Introduction
SQL Server XML Templates

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


SQL Server 2000 And XML Part 6 - Annotated XDR Schemes


Previoushome Next






SQL Server 2000 And XML Part 6 - Annotated XDR Schemes


A D V E R T I S E M E N T

 

XDR schemas provide you with a way to map the elements to their respective fields in a SQL Server table.

Annotations to the XDR schema allow you to map different elements to the fields in the database and assign your own element name attributes. Using annotations to the XDR schema is an alternative to using the XML FOR EXPLICIT mode, which is quite complex.

A schema file is built to perform the mapping of columns in your database table to the elements in an XML document. This file has a .xml extension and is in fact an XML document itself. The browser will parse a schema file as an XML document and execute any queries contained in your document.

Let's take a look at the basics for an XML schema file. As with all XML and XSL documents the first line in a schema file is the XML declaration:

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

Annotations for an XDR schema are specified in the namespace. There are actually three different namespaces that we need to include in a schema document and these namespaces are defined in the <Schema> element of the schema document.

The first of these namespaces is the Microsoft schema namespace. This defines this document as a Microsoft XDR schema document:

xmlns="urn:schemas-microsoft-com:xml-data"

The next line of code defines the namespace for data types. Using this namespace allows us to specify the data type of an element or attribute:

xmlns:dt="urn:schemas-microsoft-com:datatypes" 

The final namespace allows us to map SQL fields to attribute types in our schema document. This namespace is defined as shown in the code below:

xmlns:sql="urn:schemas-microsoft-com:xml-sql"

After all of the namespaces have been specified we define the <ElementType> element. This element provides the mapping to a table in your database. An example of this mapping is shown in the next code fragment. We specify the name attribute for this element and specify the table that this element is mapped to using the sql:relation annotation:

<ElementType name="Employee_T" sql:relation="Employee_T">

Within the <ElementType> element we specify the <AttributeType> element. This element defines an attribute type for use within the schema. We can optionally specify the data type and a default value for this attribute. In the example below the <AttributeType> element has been assigned a name of FirstName and an XML data type of bin.base64, which maps to a VarChar data type in SQL Server. The Data Type Coercions topic in the SQL Books Online provides a complete cross-reference between SQL Server data types and XML data types.

<AttributeType name="FirstName" dt:type="bin.base64" />

We use the <attribute> element to define the actual attribute and specify how it should be mapped to the database. Using the sql:field annotation, we specify the physical mapping between this element and a column in the table specified in the <ElementType> element above. The code below demonstrates how this is done:

<attribute type="FirstName" sql:field="First_Name_VC"/>

These are the basic elements required to create an annotated XDR schema. Let's move on and see how this actually works.

Try It Out - Create an Annotated XDR Schema

The schema that we want to create here will display the Software_ID and Software_Name_VC columns from the Software_T table. We will be using the sql:field annotation to map the Software_ID and Software_Name_VC columns to attributes that we define.

1. The code for the schema is listed below. Using your favorite text editor, enter the following code and save it as SoftwareSchema.xml. This XML document should be saved in the htData\Schema directory.

<?xml version="1.0" encoding="UTF-8"?>           
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">

<ElementType name="Software_T" sql:relation="Software_T">
  <AttributeType name="ID"/>
  <AttributeType name="Software"/>

  <attribute type="ID" sql:field="Software_ID"/>
  <attribute type="Software" sql:field="Software_Name_VC"/>
</ElementType>
</Schema>

2. To test this schema, enter the following URL in the browser. After the schema name we specify the table name that will supply the data to this schema. Since we have not defined a root element in the schema we must specify the root element here; in this case we have chosen a root element name of Software:

http://localhost/htData/Schema/SoftwareSchema.xml/Software
_T?Root=Software

Note the forward slash after the schema name - the syntax for calling a schema is slightly different from that for calling a template. When we execute a schema template we must specify the schema directory instead of a template directory, followed by a forward slash and then the schema name, which is just another XML document. We follow this with another forward slash followed by the table name that the schema is applied to. Finally, a question mark is inserted, followed by the parameter name Root, then an equals sign, then the name of the root element that we want to use.

The results that are displayed should be similar to those shown in the following figure. Notice that the Software_T element contains the ID attribute instead of Software_ID and the Software attribute is specified instead of Software_Name_VC:

How It Works - Create an Annotated XDR Schema

The first line of code in this schema is the XML declaration and is standard in all XML and XSL documents that we create.

The <Schema> element defines the namespaces for this schema and includes the three namespaces that we have just discussed.

<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">

We have defined the <ElementType> element next and it provides a mapping between this element and a table in the database. Here we have specified that the <attributes> defined for this element will be mapped to the Software_T table:

<ElementType name="Software_T" sql:relation="Software_T">

Next, we specify the <AttributeType> element. We have no special data types that we want these fields to represent so we take the default XML data type of bin.base64:

  <AttributeType name="ID"/>
  <AttributeType name="Software"/>

We specify the <attribute> elements next and use the sql:field annotation to map these attributes. Notice that the first attribute is the ID attribute and this has been mapped to the Software_ID column in the Software_T table. The second attribute has been mapped to the Software_Name_VC column:

 
  <attribute type="ID" sql:field="Software_ID"/>
  <attribute type="Software" sql:field="Software_Name_VC"/>

We specify the closing tags for the <ElementType> and <Schema> elements:

</ElementType>
</Schema>

Try It Out - Create a Schema Template

Having coded and executed our XDR schema we see that we are getting back to entering a lot of data in the URL. However, we can eliminate this by creating a template to execute the schema for us. This will reduce the amount of text that must be entered into the URL of the browser.

1. The template that we must code is very similar to our previous templates. The complete code for this template is listed below. Enter this code and save it as Software.xml in the Template directory:

<?xml version="1.0" encoding="UTF-8"?>
<Software xmlns:sql="urn:schemas-microsoft-com:xml-sql">
  <sql:xpath-query mapping-schema="../Schema/SoftwareSchema.xml">
   Software_T
</sql:xpath-query>
</Software>

2. To execute this template enter the following URL in your browser:

http://localhost/htData/Template/Software.xml

The results that you see are the same as for the last exercise, except that now we have executed a template that has executed a query to execute the schema. The results are shown in the following figure:

How It Works - Create a Schema Template

The first line of code in the template is the standard XML declaration. The second line of code is the root element to which we have assigned a name of Software. Within this element is the standard namespace for templates, which we have seen before:

<?xml version="1.0" encoding="UTF-8"?>
<Software xmlns:sql="urn:schemas-microsoft-com:xml-sql">

Using the <sql:xpath-query> element we specify the mapping to the schema file. Notice that since the Schema directory is at the same level as the Template directory we have specified two periods to get back to the root level of the htData virtual directory. Then we specify a forward slash and the Schema directory followed by another forward slash and the schema file.

Within the <sql:xpath-query> element we have specified the query to be executed, and the table name of Software_T. This will cause the data from the entire table to be returned.

  <sql:xpath-query mapping-schema="../Schema/SoftwareSchema.xml">
   Software_T
  </sql:xpath-query>

Lastly we close the root element by specifying the closing tag for the <Software> element:

</Software>

Summary

By now you should realize that working with XML is not all that hard. Hopefully this chapter has dispelled some of the mystique surrounding XML, and you have a better feel for what XML can do and what you can do with XML.

We have introduced some of the more common XML features of SQL Server 2000 and have shown how easy it is to access data in SQL Server using the URL of your web browser. We have displayed data in the browser as unformatted well-formed XML data and, through the use of XSL stylesheets, we have also formatted XML data.

By now you should feel comfortable using XSL stylesheets to format XML data and to display it in a web page. While we have only touched on the basics of XSL stylesheets, be aware that XSL provides many different elements that will aid you in formatting the XML data to suit your needs. Appendix F provides some links and places to go for more information on XSL and XML.

We have seen how we were able to reduce the amount of data that needs to be entered into the URL through the use of templates. We also know that templates provide better security, as we have hidden the details of the queries and the details of our database from the end user. The maintenance aspects of templates are self-evident, as we need only make the necessary changes in one place and they are immediately effective for everyone who uses the templates.

We have also seen that we can execute SQL statements directly in our templates or execute stored procedures. We have demonstrated how to do both of these and how to define and pass parameters to a template that executes a parameterized stored procedure. In the last example we also saw how a template can execute a query and use an annotated XDR schema document to process and display the results.

Having executed various queries and stored procedures in the URL you should now feel comfortable with this. You should also realize that this could be a good method of creating ad hoc queries to retrieve data formatted as XML, because a browser is available to everyone whereas the client tools for SQL Server are not.

To summarize, you should know how to:

  • Execute queries and stored procedures in the URL to return XML data
  • Execute queries and stored procedures in a template to return XML data
  • Create and use XSL stylesheets to format XML data
  • Create and use templates
  • Create and use an annotated XDR schema


Be the first one to comment on this page.




  SQL Server eBooks

No eBooks on SQL Server could be found as of now.

 
 SQL Server FAQs
More Links » »
 
 SQL Server Interview Questions
More Links » »
 
 SQL Server Articles
More Links » »
 
 SQL Server News
More Links » »
 
 SQL Server Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: SQL Server 2000 And XML Part 6 - Annotated XDR Schemes, SQL Server, SQL Server, SQL Server Tutorial, SQL Server tutorial pdf, history of SQL Server, SQL Server Administration, learn SQL Server

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright © 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright © 2003-2017 Vyom Technosoft Pvt. Ltd., All Rights Reserved.