XML Schema helps you model (1)

xiaoxiao2021-03-06  91

XML Schema is a recommended standard for W3C (World Wide Web Alliance), officially released in May 2001. After several years of large-scale discussions and development, it is now laid, and it is the preferred data modeling tool in the world's recognized XML environment.

Since XML is a subset of SGML (standard universal label language), it also inherits SGML for modeling DTD. The advantage of using DTD is to take advantage of a large number of existing DTD tools, making it a relatively low level to develop applications. However, DTD has many shortcomings:

1. DTD is based on regular expressions, and the description ability is limited;

2. DTD does not have data type support, in most applications;

3. DTD constraint definition ability, unable to make more detailed semantic restrictions on XML instance documents;

4. DTD is not structured, the cost of reuse is relatively high;

5. DTD is not using XML as a descriptor, while the DTD is built and accessed does not have standard programming interfaces, and DTD maintenance cannot be performed using standard programming.

XML Schema is designed for the shortcomings of these DTDs, which use XML as a descriptor, which has strong description capabilities, extension capabilities, and processing maintenance.

Introduction to XML Schema

The main purpose of XML Schema is to define a class XML document (an XML Application). Therefore, the "example document" form of the mode is often used to describe an XML document consistent with a particular XML Schema. In fact, document instances and Schema documents do not exist in the form of documents, which can exist in the form of byte streams transmitted between applications, or as a collection of database records and XML "information items". However, in order to simplify the entry, we always regard examples and patterns as documentation or files, think they always exist in the form of a document instance or a mode document.

Here we will combine an example to make a simple summary of XML Schema, I hope that you can use the usage method for the initial master of this section and the specific semantics of the XML Schema document instance. XML Schema is a basic tool for web services technology, but not all features of XML Schema will be used extensively, and therefore, this article will not be introduced for the system of XML Schema.

Before introducing the XML Schema syntax, first consider an XML instance document PO.xml. It describes a home product purchase order generated by home product procurement / payment applications (see Code 1).

alice smith

123 MAPLE Street

Mill Valley

CA

90952

robert smith

8 Oak Avenue

Old Town

PA

95819

Hurry, My Lawn is Going Wild!

Lawnmower

1

148.95

confirm this is electric literary

Baby Monitor

1

39.98

1999-05-21

This purchase order consists of a heel element PurchaseORDER and its sub-elements Shipto, BillTo, Comment and Items. These sub-elements (except for Comment) also contain some other child elements.

The leaf element is included in a number rather than any child element, such as a child element such as USPRice. Elements are called composite types if they contain sub-elements or with attributes; vice verses if only numbers, strings, or other data, etc., but are not included in the simple type. In this instance document, the composite type and some simple types are defined in the mode document that purchase the order, while the simple types of other standards are the form of simple types built in XML Schema.

Introduce the contact between the purchase order instance document and the mode document before studying the purchase order mode documentation of this instance document. An instance document actually does not necessarily need a reference mode document. Of course, in fact, many instance documents do reference the mode document, in order to make the entry make it simpler, and we choose not to reference. At the same time, it is assumed that the processor of any instance document does not receive any information from the purchase order instance document, and can also correctly purchase the order mode document.

Purchase order mode documentation

At code 2, the mode document for purchasing orders is given. Document PO.xSD Before giveing ​​an explanation, you can use XML knowledge to try to understand this mode document.

Purchase Order Schema for Example.com.

Copyright 2000 Example.com. All Rights Reserved.

Fixed = "us" />

Purchase Order Mode Document consists of a Schema element and a series of sub-elements. Most sub-elements are Element, ComplexType, and SimpleType, which determines the expression and content of the elements in the instance document, everyone can read Element, ComplexType, SimpleType These elements, these will be several elements we have always needed.

At the same time, you can declare XMLns: XSD = "http://www.w3.org/2001/xmlschema" by using the namespace in the Schema element, making each element in the pattern document has a namespace with XML Schema Contact Name Space Prefix "XSD:". Although in the grammatical, any prefix form can be used, but the namespace prefix "XSD:" is agreed to represent the XML Schema namespace. Since the same prefix is ​​used, the same association will appear in the name of the built-in simple type, such as XSD: String. This form of association is to indicate that the current element or simple type is built-in definition of XML Schema language instead of a mode document author's own vocabulary. In order to clearly and briefly, we only mention the names and simple type names of elements, and ignore their prefix "XSD:".

转载请注明原文地址:https://www.9cbs.com/read-96783.html

New Post(0)