Home Backend Development XML/RSS Tutorial Create an XML view using an annotated XDR schema

Create an XML view using an annotated XDR schema

Mar 01, 2017 pm 04:44 PM

XML views of relational data can be created using the XDR (xml-Data simplified) schema. These views can then be queried using XPath queries. This is similar to using the CREATE VIEW statement to create a view and specify a SQL query against the view.
XML Schema describes the structure of an XML document and the different constraints on the data in the document. When you specify an XPath query against a schema, the structure of the returned XML document is determined by the schema against which the XPath query was performed.
In Microsoft® SQL Server™ 2000, use the simplified XML-Data (XDR) language to create the schema. XDR is a flexible language that overcomes some of the limitations of document type definitions (DTDs) used to describe the structure of documents. Unlike DTDs, XDR schemas describe document structure using the same syntax as XML documents. Additionally, in a DTD, all data content is character data. The XDR language schema enables you to specify the data type of an element or attribute.
In XDR Schema, the element contains the entire schema. As attributes of the element, you can describe the attributes that define the name of the schema and the namespace in which the schema resides. In the XDR language, all element declarations must be enclosed in a element.
The minimal XDR schema is as follows:

<?xml version="1.0" ?> 
<Schema xmlns="urn:schemas-microsoft-com:xml-data"> 
   ... 
</Schema> 
<Schema> 元素是从 xml-data 命名空间 (urn:schemas-microsoft-com:xml-data) 派生出的。
Copy after login

Description This document assumes that you are familiar with the XML-Data language.
Annotations for XDR Schema
You can use annotations in the XDR schema that describe the mapping to the database to query the database and return the results in an XML document format. SQL Server 2000 introduced a number of annotations that can be used to map XDR schemas to tables and columns in the database. You can specify XPath queries on XML views created by an XDR schema to query the database and obtain results in XML format.
This is an alternative to the more complex SQL query writing process, which uses the FOR XML EXPLICIT pattern to describe the XML document structure as part of the query. For more information about using FOR XML EXPLICIT mode in SELECT queries, see Using EXPLICIT Mode. However, to overcome most limitations of XPath queries on mapping schemas, use FOR XML EXPLICIT mode for SQL queries that return results in XML document format.
If you have a public XDR schema (such as the Microsoft BizTalk™ schema), you can do any of the following:
· Write a query in FOR XML EXPLICIT mode so that the generated data is valid for the public XDR schema; however, write FOR XML EXPLICIT queries can be cumbersome.
· Make a private copy of a public XDR schema. The annotations are then added to the private replica, resulting in a mapping schema. You can specify an XPath query for the mapping schema. The query produces data in the common schema namespace. Creating an annotated schema and specifying an XPath query against that schema is a much simpler process than writing complex FOR XML EXPLICIT queries. The image below illustrates this process.

Description The Microsoft BizTalk™ framework is designed to define a standard XML format for common business objects such as contracts, orders, and appointments. Copies of these business architectures can be found at http://biztalk.org/BizTalk/default.asp.
Mapping Schema
In the context of a relational database, it is very useful to map an arbitrary XDR schema to a relational store. One way to achieve this is to annotate XDR schemas. The annotated XDR schema is called a "mapping schema" and provides information about how XML data is mapped to a relational store. A mapping schema is actually an XML view of relational data. You can use these mappings to retrieve relational data in XML document format.
Microsoft SQL Server 2000 introduced a number of annotations that can be used in XDR schemas to map elements and attributes to database tables and columns. You can use XPath (XML path) to specify queries to the mapping schema (XML view). The mapping schema describes the resulting document structure.
Namespace of annotations
In XDR schema, use the following namespace to specify annotations: urn:schemas-microsoft-com:xml-sql.
The following example shows that the simplest way to specify a namespace is to specify it in the tag. urn:schemas-microsoft-com:xml-sql Namespace annotations must be namespace qualified.

<?xml version="1.0" ?> 
<Schema xmlns="urn:schemas-microsoft-com:xml-data" 
        xmlns:sql="urn:schemas-microsoft-com:xml-sql" 
               > 
    ........... 
</Schema>
Copy after login

The namespace prefix used is arbitrary. In this documentation, the sql prefix is ​​used to denote an annotation namespace and to distinguish annotations in this namespace from annotations in other namespaces.
Namespace of data types
The XDR schema allows you to specify the data type of an element or attribute. Use the following namespace to specify data types: urn:schemas-microsoft-com:datatypes.
The following is the minimal XDR schema with namespace declaration:

<?xml version="1.0" ?> 
<Schema xmlns="urn:schemas-microsoft-com:xml-data" 
        xmlns:sql="urn:schemas-microsoft-com:xml-sql" 
        xmlns:dt="urn:schemas-microsoft-com:datatypes"> 
   ... 
</Schema>
Copy after login

所用的命名空间前缀是任意的。 在本文档中,dt 前缀用于表示数据类型命名空间和使此命名空间中的批注区别于其它命名空间中的批注。
元素来源于 xml-data 命名空间:urn:schemas-microsoft-com:xml-data。
XDR 架构示例
下例显示如何将批注添加到 XDR 架构中。XDR 架构由 元素和 EmpID、Fname 及 Lname 特性组成。

<?xml version="1.0" ?> 
<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="Employee" > 
    <AttributeType name="EmpID" /> 
    <AttributeType name="FName" /> 
    <AttributeType name="LName" />
    <attribute type="EmpID" /> 
    <attribute type="FName" /> 
    <attribute type="LName" /> 
</ElementType> 
</Schema>
Copy after login

现在,将批注添加到此 XDR 架构中,使架构的元素和特性映射到数据库的表和列。 带批注的 XDR 架构如下:

<?xml version="1.0" ?> 
<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="Employee" sql:relation="Employees" > 
    <AttributeType name="EmpID" /> 
    <AttributeType name="FName" /> 
    <AttributeType name="LName" />
    <attribute type="EmpID" sql:field="EmployeeID" /> 
    <attribute type="FName" sql:field="FirstName" /> 
    <attribute type="LName" sql:field="LastName" /> 
</ElementType> 
</Schema>
Copy after login

在此映射架构中,使用 sql:relation 批注将 元素映射到 Employees 表。使用 sql:field 批注将特性 EmpID、Fname 和 Lname 映射到 Employees 表中的 EmployeeID、FirstName 和 LastName 列。 
此带批注的 XDR 架构提供关系数据的 XML 视图。使用 Xpath(XML 路径)语言可以查询该 XML 视图。Xpath 查询返回 XML 文档形式的结果,而不是 SQL 查询所返回的行集。 
  
说明  在映射架构中,指定的关系值(如表名和列名)区分大小写。

以上就是使用带批注的 XDR 架构创建 XML 视图的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the conversion speed fast when converting XML to PDF on mobile phone? Is the conversion speed fast when converting XML to PDF on mobile phone? Apr 02, 2025 pm 10:09 PM

The speed of mobile XML to PDF depends on the following factors: the complexity of XML structure. Mobile hardware configuration conversion method (library, algorithm) code quality optimization methods (select efficient libraries, optimize algorithms, cache data, and utilize multi-threading). Overall, there is no absolute answer and it needs to be optimized according to the specific situation.

How to convert XML files to PDF on your phone? How to convert XML files to PDF on your phone? Apr 02, 2025 pm 10:12 PM

It is impossible to complete XML to PDF conversion directly on your phone with a single application. It is necessary to use cloud services, which can be achieved through two steps: 1. Convert XML to PDF in the cloud, 2. Access or download the converted PDF file on the mobile phone.

How to convert XML to PDF on your phone? How to convert XML to PDF on your phone? Apr 02, 2025 pm 10:18 PM

It is not easy to convert XML to PDF directly on your phone, but it can be achieved with the help of cloud services. It is recommended to use a lightweight mobile app to upload XML files and receive generated PDFs, and convert them with cloud APIs. Cloud APIs use serverless computing services, and choosing the right platform is crucial. Complexity, error handling, security, and optimization strategies need to be considered when handling XML parsing and PDF generation. The entire process requires the front-end app and the back-end API to work together, and it requires some understanding of a variety of technologies.

Is there any mobile app that can convert XML into PDF? Is there any mobile app that can convert XML into PDF? Apr 02, 2025 pm 08:54 PM

An application that converts XML directly to PDF cannot be found because they are two fundamentally different formats. XML is used to store data, while PDF is used to display documents. To complete the transformation, you can use programming languages ​​and libraries such as Python and ReportLab to parse XML data and generate PDF documents.

How to open web.xml How to open web.xml Apr 03, 2025 am 06:51 AM

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

Recommended XML formatting tool Recommended XML formatting tool Apr 02, 2025 pm 09:03 PM

XML formatting tools can type code according to rules to improve readability and understanding. When selecting a tool, pay attention to customization capabilities, handling of special circumstances, performance and ease of use. Commonly used tool types include online tools, IDE plug-ins, and command-line tools.

How to open xml format How to open xml format Apr 02, 2025 pm 09:00 PM

Use most text editors to open XML files; if you need a more intuitive tree display, you can use an XML editor, such as Oxygen XML Editor or XMLSpy; if you process XML data in a program, you need to use a programming language (such as Python) and XML libraries (such as xml.etree.ElementTree) to parse.

How to export pdf with xml How to export pdf with xml Apr 03, 2025 am 06:45 AM

There are two ways to export XML to PDF: using XSLT and using XML data binding libraries. XSLT: Create an XSLT stylesheet, specify the PDF format to convert XML data using the XSLT processor. XML Data binding library: Import XML Data binding library Create PDF Document object loading XML data export PDF files. Which method is better for PDF files depends on the requirements. XSLT provides flexibility, while the data binding library is simple to implement; for simple conversions, the data binding library is better, and for complex conversions, XSLT is more suitable.

See all articles