Use SQLXML 3.0 (Web Services, XML Views, Managed Classes)
Mood
2002-5-25
Article Type: Overview
Difficult Level: 5/9
Version: 4.16
Various ways to access SQL Server using HTTP
First we can access SQL 2000 through the HTTP protocol, and use the For XML of the Transact-SQL SELECT statement in SQL 2000, you can directly execute the SQL statement and generate an XML document from the database, and return to the requester.
Basically we can use five ways through the HTTP protocol to get an XML document directly:
1. Place the SQL query statement in the URL.
Such as the URL below:
http: // ibmthinka30 / northwind /? SQL = SELECT * FROM EMPLOYEES for XML Auto & Root = root
2. Specify a template directly in the URL.
For example, the following is to specify a template file directly in the URL (honestly said that URL is too long, first COPY is going down again)
http: // ibmthinka30 / northwind? Template =
3. Indicate through a template in the URL.
In this way, it is necessary to set up in advance, just like the WebService mode above, we first create a directory, then set, such as the actual directory (PATH) is: D: / myProject / SQLXMLVDIR / Northwind / Templates, Directory Name called: Templates; Select Types: Templates
Then we quickly create a test template file in this directory, such as: SECTEMPLOYEES.XML.
It can be the content of the URL above:
We can enter such a URL: http://ibmthinka30/northwind/templates/selectemplanyees.xml
4. A XPath query is performed on the map file specified by the URL.
This way also needs to be pre-set, just like the template mode above, we create a directory first, then set, such as the actual directory (PATH) is: D: / MyProject / SQLXMLVDIR / Northwind / Schemas, Directory name: Schemas; Select type is: schema
Then create a template file (or Schema file), for example: EmployeesXPath.xml
XML Version = "1.0"?>
http://ibmthinka30/northwind/schemas/employeesxpath.xml/employees [@ EmployeeID = "3"]
5. Specify the database object directly in the URL (if you know).
This feature we must first set a new directory name (name) is: DBObject, its type (TYPE) is: DBOBJECT. At present, it is only limited to single-line single columns in a single table, you need to specify the column name. This method is almost rarely applied because it is almost specifically designed for a single column of binary databases.
For example: http: // ibmthinka30 / northwind / dbobject / employees [@ EmployeeID = '1'] / @photo
Or http: // ibmthinka30 / northwind / dbobject / EMPLOYEES [@ Employeeid = '6'] / @firstname
The actual application is more encouraged to use templates, using templates and direct SQL statements, the template file can complete such functions:
1. Perform SQL query and XPath query.
2. Pass the parameters to the SQL statement of the template.
3. Specify a root element for the returned XML document.
4. Apply the XSL file for the result of the returned result.
5. Specify the namespace for the returned XML document.
This is not only because the template can complete more features, but also safer and packaged. The template is an XML document based on Microsoft XML-SQL namespace, which typically includes at least one SQL query statement. Through the directory corresponding to the virtual name, we can manage these templates, and the user accesses data by specifying a template name. As we see when we are setting, its type (TYPE) is: Template, which generally corresponds to SQLXMLCommandType.Template or SQLXMLCommandType.Template in the DOTNET Class API function. Templates are the most commonly used methods that allow users to browse data based on web applications. Of course there is another template file, here we call it as a map file. The mapping file is a Schema-based XML document. Now we can map elements or properties in Schema to the tables and columns of the database. Then we can use the map file to retrieve the database data, but if these Schema files are used to define the B2B application of trade exchange, then you can now add some simple annotate to the Schema file, which is transparent Map the data in the XML document to the tables and columns in the database. The type of this file is typically Schema, which is usually used in the DOTNET Class API function. The mapping file can be used to create an XML View, SQL 2000 supports XML database access via XML View. This is like the past we have established a database view in SQL 2000, then query this view through SQL, and now we create an XML view of a database, then query the data in this view via XPath. Map files and template files are different from them to define different format definition languages, and mapping files are not simply used to retrieve data. Adhering to the biggest advantage of Schema is that it has more data types and more for our unified programming (such as generating a corresponding class). The next question is how to generate this annotated XSD Schemas? This is what we have to see below.
Special Note:
This article original, 9CBS signature start, all text and photo copyright. Do not propagate, reprint, or adaptation without authorization.
If you have any questions or suggestions, please email new2001@msn.com