An example of a simple XML Schema

Source: Internet
Author: User

As we can see, the syntax of DTD is quite complex, and it does not conform to the standards of XML files and is a self-contained system. That is to say, the DTD document itself is not a good XML document. The above introduction to the DTD is just an introduction, the purpose is to help you understand the DTD file and create a simple DTD file when necessary, because many XML applications are built on the DTD.

Another alternative to DTD is the schema defined by W3C. The schema can be translated into a pattern, outline, plan, and plan literally. It basically means creating a pattern for the XML document.

The obvious advantage of Schema over DTD is that the XML schema document itself is also an XML document, rather than using a self-contained syntax like a DTD. This facilitates users and developers, because they can use the same tool to process XML schema and other XML Information, rather than using special tools for schema. Schema is easy to understand. Anyone who understands XML syntax and rules can understand it immediately. The concept of schema has been put forward for a long time, but W3C standards have only recently come out, and the corresponding application support is not yet complete, but the adoption of schema has become a trend of XML development.

First, let's start with the simplest example to learn the Schema syntax structure:

For example, a simple XML document is as follows:

<Books>
<Name> Tianya Mingyue Dao
<Author> Gu Long

If the structure of the XML document is defined in the form of a DTD, it can be as follows:

<! Element book (name, author)>
<! Element name (# pcdata)>
<! Element author (# pcdata)>

How can we define a schema? See the followingCode:

<Element name = 'book' type = 'book type'/>
<Complextype name = 'book type'>
<Element name = 'name' type = 'string'/>
<Element name = 'authorization' type = 'string'/>
</Complextype>

It can be noted that in the schema, the definition of the nature and content of the entire document is also implemented through the definition of elements and element relations. In the schema, the element is determined by its name and content model. The name is the name of the element, which can be understood by everyone, the content model actually represents the element type. Just like in C ++, we can define a variable at will, but the type of the variable must be defined. The type of the variable may have multiple forms, it can be a simple variable (such as the type specified inside C ++, bool, Int, double, Char, etc ), it can also be a very complex type (such as a struct or class). It is also the same in schema. type can be divided into two forms, one is a very simple type, simple, a complex type, called complex. Simple types cannot contain elements and attributes. (Note that the schema and DTD have the same element attributes. The greatest truths are the same ). Complex types can contain not only attributes, but also other elements, or they can be associated with attributes in other elements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.