search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

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 <Schema> element contains the entire schema. As attributes of the <Schema> 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 <Schema> element.
The minimal XDR schema is as follows:

&lt;?xml version=&quot;1.0&quot; ?&gt; 
&lt;Schema xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot;&gt; 
   ... 
&lt;/Schema&gt; 
&lt;Schema&gt; 元素是从 xml-data 命名空间 (urn:schemas-microsoft-com:xml-data) 派生出的。

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 <Schema> tag. urn:schemas-microsoft-com:xml-sql Namespace annotations must be namespace qualified.

&lt;?xml version=&quot;1.0&quot; ?&gt; 
&lt;Schema xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot; 
        xmlns:sql=&quot;urn:schemas-microsoft-com:xml-sql&quot; 
               &gt; 
    ........... 
&lt;/Schema&gt;

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:

&lt;?xml version=&quot;1.0&quot; ?&gt; 
&lt;Schema xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot; 
        xmlns:sql=&quot;urn:schemas-microsoft-com:xml-sql&quot; 
        xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot;&gt; 
   ... 
&lt;/Schema&gt;

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

&lt;?xml version=&quot;1.0&quot; ?&gt; 
&lt;Schema xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot; 
        xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; 
        xmlns:sql=&quot;urn:schemas-microsoft-com:xml-sql&quot;&gt;
&lt;ElementType name=&quot;Employee&quot; &gt; 
    &lt;AttributeType name=&quot;EmpID&quot; /&gt; 
    &lt;AttributeType name=&quot;FName&quot; /&gt; 
    &lt;AttributeType name=&quot;LName&quot; /&gt;
    &lt;attribute type=&quot;EmpID&quot; /&gt; 
    &lt;attribute type=&quot;FName&quot; /&gt; 
    &lt;attribute type=&quot;LName&quot; /&gt; 
&lt;/ElementType&gt; 
&lt;/Schema&gt;

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

&lt;?xml version=&quot;1.0&quot; ?&gt; 
&lt;Schema xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot; 
        xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; 
        xmlns:sql=&quot;urn:schemas-microsoft-com:xml-sql&quot;&gt;
&lt;ElementType name=&quot;Employee&quot; sql:relation=&quot;Employees&quot; &gt; 
    &lt;AttributeType name=&quot;EmpID&quot; /&gt; 
    &lt;AttributeType name=&quot;FName&quot; /&gt; 
    &lt;AttributeType name=&quot;LName&quot; /&gt;
    &lt;attribute type=&quot;EmpID&quot; sql:field=&quot;EmployeeID&quot; /&gt; 
    &lt;attribute type=&quot;FName&quot; sql:field=&quot;FirstName&quot; /&gt; 
    &lt;attribute type=&quot;LName&quot; sql:field=&quot;LastName&quot; /&gt; 
&lt;/ElementType&gt; 
&lt;/Schema&gt;

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

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


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

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

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)

How to convert XML to YAML for DevOps? (Configuration Management) How to convert XML to YAML for DevOps? (Configuration Management) Mar 12, 2026 am 12:11 AM

xmltodict PyYAMListhesafestcomboforDevOpsconfigfilesbecauseitpreservescomments,CDATA,namespaces,andattributesaccurately,unlikerawXML-to-YAMLtoolsorCLIutilitieslikeyqandxmllintwhichsilentlydropcriticalmetadata.

How to convert an XML file to a Word document? (Reporting) How to convert an XML file to a Word document? (Reporting) Mar 09, 2026 am 01:05 AM

python-docx does not support direct reading of XML files. You need to use xml.etree.ElementTree or lxml to parse the XML extraction fields first, and then write them into the Document object segment by segment. Explicit declaration of prefixes is required to process namespaces, and manual manipulation of the underlying XML is required for table merging and styling. Chinese paths should be avoided when saving.

How to parse XML data from a URL API? (Rest Services) How to parse XML data from a URL API? (Rest Services) Mar 13, 2026 am 12:06 AM

To parse remote XML API in Python, you need to use requests to get the response and then check the status code and Content-Type. Prioritize using r.text with xml.etree.ElementTree to parse; when encountering a namespace, you need to pass the namespace dictionary; use iterparse to stream large files and clear them manually; front-end JS requires CORS support or proxy.

How to minify XML files for faster web loading? (Performance Optimization) How to minify XML files for faster web loading? (Performance Optimization) Mar 08, 2026 am 12:16 AM

RunningminifyonXMLwithoutunderstandingitsrulesbreaksparsingoralterssemanticsbecausewhitespacecanbemeaningful;safeminificationrequiresdata-orientedXML,controlledgeneration/consumption,andstrictparserawareness.

How to use Attributes vs Elements in XML? (Design Best Practices) How to use Attributes vs Elements in XML? (Design Best Practices) Mar 16, 2026 am 12:26 AM

You should use attributes to store short metadata (such as id, type), and use elements to store scalable content data; because attributes do not support namespaces, duplication, nesting, and internationalization, their parsing is error-prone and maintenance is difficult.

How to open and view XML files in Windows 11? (Beginner Guide) How to open and view XML files in Windows 11? (Beginner Guide) Mar 12, 2026 am 01:02 AM

The XML file cannot be opened by double-clicking because it is associated with Notepad by default, causing confusion in the display. You should use Notepad, VSCode or Edge instead; Edge can format and report errors, while VSCode requires the installation of extensions such as RedHatXML for normal highlighting, indentation and verification.

How to read XML data in C# using LINQ? (.NET Development) How to read XML data in C# using LINQ? (.NET Development) Mar 15, 2026 am 12:43 AM

XDocument.Load() is the preferred method for reading local XML files and automatically handles encoding, BOM and format exceptions; absolute or correct relative paths are required; namespaces must be explicitly declared and participate in queries; Elements() and Descendants() behave differently and should be selected as needed; string parsing must capture XmlException and verify the source.

How to read XML configuration in Spring Boot? (Java Framework) How to read XML configuration in Spring Boot? (Java Framework) Mar 13, 2026 am 12:17 AM

SpringBoot loads XML configuration files through the @ImportResource annotation, which needs to be used with the @Configuration class. It supports classpath relative paths and multi-file arrays, but you need to manually register the PropertySourcesPlaceholderConfigurer and declare the context namespace to parse placeholders.

Related articles