XML Views Based on Annotated XDR Schemas in .NET framework

Generating Data Matrix in .NET framework XML Views Based on Annotated XDR Schemas

XML Views Based on Annotated XDR Schemas
Data Matrix ECC200 Recognizer In Visual Studio .NET
Using Barcode Control SDK for .NET framework Control to generate, create, read, scan barcode image in .NET framework applications.
ECC200 Maker In .NET
Using Barcode creator for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in .NET applications.
The Using Schemas and XPath Queries section, earlier in the chapter, demonstrated how XDR schemas and XPath queries can be used to retrieve data from a database. This section now examines in greater detail the use of XDR schemas for mapping. The main purpose of an XDR schema is to define the structure of the XML document. SQL Server 2000 extends the XDR schema language with annotations designed to map XML nodes (elements and attributes) and database objects (tables, views, and columns). Other annotations enable features such as the definition of hierarchical relationships between XML nodes, the change of a target namespace, and the retrieval of XML-encoded data from a database. Such XDR schemas produce XML documents that behave in a fashion similar to database views and, therefore, are sometimes called XML views. The basic idea is that all metadata needed to generate and validate an XML document should be stored in one place a schema document. The basic features of schemas define the structure, and annotations-based features extend that definition by providing mapping information.
ECC200 Reader In .NET Framework
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
Barcode Creator In VS .NET
Using Barcode printer for .NET framework Control to generate, create barcode image in VS .NET applications.
Mapping Tables, Views, and Columns
Barcode Reader In VS .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
Making ECC200 In Visual C#.NET
Using Barcode generator for .NET Control to generate, create ECC200 image in .NET applications.
The XDR schema used in the Using Schemas and XPath Queries section was based on default mapping between tables and elements, and between columns and attributes. Because SQL Server was able to find a table that corresponded to the specified element and attributes that corresponded to the table s columns, the result was an XML document containing information from the database table.
Generate Data Matrix ECC200 In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create Data Matrix ECC200 image in ASP.NET applications.
Data Matrix 2d Barcode Drawer In VB.NET
Using Barcode creation for VS .NET Control to generate, create Data Matrix ECC200 image in VS .NET applications.
SQL Server 2000 Stored Procedure & XML Programming
Code 39 Generator In VS .NET
Using Barcode generation for .NET Control to generate, create Code 3/9 image in Visual Studio .NET applications.
Creating UPC A In Visual Studio .NET
Using Barcode drawer for .NET Control to generate, create UPC-A Supplement 5 image in .NET framework applications.
In the case in which an element is named differently than a table (or a view), you must add a sql:relation annotation (an attribute of the <ElementType> tag) to the XDR schema. In the case in which attributes of the element are named differently than the columns of the table (or the view), you must add a sql:field annotation (an attribute of the <attribute> tag) to the schema. In the following example, the Equipment table is mapped to the element Part, and the columns EquipmentId and Make are mapped to the attributes PartNum and Manufacturer:
ECC200 Drawer In VS .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create ECC200 image in VS .NET applications.
ISSN - 13 Creation In Visual Studio .NET
Using Barcode generator for VS .NET Control to generate, create ISSN image in VS .NET applications.
<Schema name="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="Part" sql:relation="Equipment" content="empty" model="closed"> <AttributeType name="PartNum" dt:type="i4" /> <AttributeType name="Manufacturer" dt:type="string" /> <AttributeType name="Model" dt:type="string"/> <attribute type="PartNum" sql:field="EquipmentId"/> <attribute type="Manufacturer" sql:field="Make"/> <attribute type="Model"/> </ElementType> </Schema>
Recognizing Data Matrix 2d Barcode In C#
Using Barcode decoder for .NET Control to read, scan read, scan image in VS .NET applications.
Recognizing Bar Code In Java
Using Barcode Control SDK for Eclipse BIRT Control to generate, create, read, scan barcode image in BIRT applications.
The following template can use the preceding schema:
Data Matrix Maker In Objective-C
Using Barcode drawer for iPhone Control to generate, create ECC200 image in iPhone applications.
Code-39 Creator In None
Using Barcode maker for Software Control to generate, create Code 39 image in Software applications.
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:xpath-query mapping-schema="PartSchema.xml"> Part </sql:xpath-query> </ROOT>
DataMatrix Maker In None
Using Barcode generation for Font Control to generate, create ECC200 image in Font applications.
Reading Data Matrix ECC200 In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
The result is shown in Figure 14-18. sql:field annotations can be applied to elements as well. The following schema is not attribute-based, but element-based:
Bar Code Maker In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Barcode Scanner In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
<Schema name="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="Part" sql:relation="Equipment" content="eltOnly" model="closed" order="many"> <element type="PartNo" sql:field="EquipmentId"/> <element type="Manufacturer" sql:field="Make"/>
14: Publishing Information Using SQLXML
<element type="Model"/> </ElementType> <ElementType name="PartNo" content="textOnly" model="closed" dt:type="i4"/> <ElementType name="Manufacturer" content="textOnly" model="closed" dt:type="string"/> <ElementType name="Model" content="textOnly" model="closed" dt:type="string"/> </Schema>
You can use this schema through the following template:
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:xpath-query mapping-schema="PartElementSchema.xml"> Part </sql:xpath-query> </ROOT>
The result is shown on the following page in Figure 14-19.
Figure 14-18
The result of the annotated schema
SQL Server 2000 Stored Procedure & XML Programming
Figure 14-19
An element-based XML document as a result of an annotated schema
Required Namespaces
All XDR schemas are defined in the urn:schemas-microsoft-com:xmldata namespace. Therefore, each schema must contain a reference to that namespace. The XDR data types are defined in the urn:schemas-microsoftcom:datatypes namespace. SQL Server annotations that allow you to map relational objects with XML components are defined in the urn:schemasmicrosoft-com:xml-sql namespace. The typical XDR schema needs a root element similar to the following:
<Schema name="Schema" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes" xmlns:sql="urn:schemas-microsoft-com:xml-sql"> ... </Schema>
14: Publishing Information Using SQLXML
Mapping Relationships
So far, I have demonstrated only schemas based on a single table (or view). When the XML document has to map to more than one table, that relationship has to be annotated using the <sql:relationship> tag. This process is similar to the creation of foreign keys in relational databases. The following attributes of the <sql:relationship> tag need to be defined: Attribute
key-relation key foreign-key
Description
Name of the primary relation Node (field) in a primary relation (table) that serves as the primary key Node (field) in a foreign relation (table) that serves as the foreign key
foreign-relation Name of the foreign relation (table)
The following schema contains the definition for a relationship between the Contact and Inventory elements:
<Schema name="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="Contact" content="eltOnly" model="closed" order="many"> <element type="Inventory" maxOccurs="*"> <sql:relationship key-relation="Contact" key="ContactId" foreign-key="OwnerId" foreign-relation="Inventory" /> </element> <AttributeType name="ContactId" dt:type="i4"/> <AttributeType name="FirstName" dt:type="string"/> <AttributeType name="LastName" dt:type="string"/> <AttributeType name="Phone" dt:type="string"/> <AttributeType name="Fax" dt:type="string"/> <AttributeType name="Email" dt:type="string"/> <AttributeType name="OrgUnitId" dt:type="i2"/> <AttributeType name="UserName" dt:type="string"/> <AttributeType name="ts" dt:type="i8"/> <attribute type="ContactId"/>
Copyright © OnBarcode.com . All rights reserved.