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 parse XML in Ruby on Rails? (Web Frameworks) How to parse XML in Ruby on Rails? (Web Frameworks) Jan 05, 2026 am 12:53 AM

UseNokogiriforfast,robustXMLparsinginRails:installviagem'nokogiri',parsewithNokogiri::XML,handleencoding/namespacesexplicitly,andextractdatasafelyusingcss()/xpath()whilecheckingdoc.errorsand.textguards.

How to compare two XML files and find differences How to compare two XML files and find differences Jan 05, 2026 am 01:05 AM

Use tools or programming methods to compare XML file differences: first use online tools (such as xmlcompare.org) or IDE plug-ins for visual comparison, and then implement automated analysis through the command line (such as xmllint diff) or Python scripts (using the lxml library to parse and standardize XML). Pay attention to the processing of whitespace characters, attribute order, namespace prefixes and other influencing factors. It is recommended to use CanonicalXML to eliminate format differences.

How to fix XML encoding issues (UTF-8)? (Character Sets) How to fix XML encoding issues (UTF-8)? (Character Sets) Jan 03, 2026 am 02:48 AM

XMLshowsgarbledtextwhendeclaredUTF-8encodingmismatchesactualbyteencoding;verifywithfile-iorxxd,fixbyresavingcorrectly,andparseinbinarymodetohonortheXMLdeclaration.

The Role of XML in modern configuration files (e.g., pom.xml, web.config) The Role of XML in modern configuration files (e.g., pom.xml, web.config) Jan 02, 2026 am 12:59 AM

XMLremainswidelyusedinmodernconfigurationfilesduetoitsstructured,hierarchicaldatarepresentation,enablingclearparent-childrelationshipsandmetadatastorageviatagsandattributes,asseeninpom.xmlandweb.config.2.ItsupportsformalvalidationthroughXSDandDTDsche

How to serialize C# objects to XML? (Data Persistence) How to serialize C# objects to XML? (Data Persistence) Jan 04, 2026 am 01:41 AM

XmlSerializerisidealforsimple,attribute-drivenXMLserializationinC#,requiringpublicproperties,parameterlessconstructors,andconcretetypes;itignores[Serializable],supportsListbutnotDictionary,lackscircularreferencehandling,andneedsexplicitnull/namespace

How to manage dependencies with a pom.xml in Maven How to manage dependencies with a pom.xml in Maven Jan 03, 2026 am 01:42 AM

The pom.xml file declares dependencies through groupId, artifactId and version, and can use scope to specify the scope; 2. Multi-module projects use dependencyManagement to unify versions; 3. Maven automatically handles transitive dependencies, and exclusions can be used to exclude conflicting libraries; 4. Use MavenVersionsPlugin to check dependency updates to keep projects safe and consistent.

How to delete specific nodes from XML in Java? (DOM Manipulation) How to delete specific nodes from XML in Java? (DOM Manipulation) Jan 07, 2026 am 12:14 AM

To delete a specific node, you need to operate based on the tag name and conditions (such as attribute values ​​or text content): the liveNodeList must be traversed in reverse order and removeChild() is called; XPath is recommended for complex conditions; be sure to check that the parent node is not empty before deleting to avoid NPE; performance and memory limitations should be considered for large-scale deletions.

How to deserialize XML into a C# object How to deserialize XML into a C# object Jan 02, 2026 am 12:45 AM

Use the XmlSerializer class to deserialize XML into a C# object. You need to define a class that matches the XML structure and annotate it with attributes such as XmlElement and XmlAttribute. Then read the XML stream and convert it into an object instance through the Deserialize method.

Related articles