A brief introduction to XML Schema

黄舟
Release: 2017-03-27 16:42:16
Original
1440 people have browsed it

XML Schema is the same as DTD (DTD syntax overview). It also constrains a type of XML document and determines its structure, elements, attributes, and type of data. And the constraints on the elements, entities, attributes of elements, and relationships between elements and entities used in XML documents. XML Schema was first proposed by Microsoft and has been accepted by W3C as a standard. Different from DTD, XML Schema files use XML syntax. Its design purposes are many similar to DTD, but it surpasses DTD in terms of functionality and extensibility. Let’s talk about some of the differences between them:

1. XML Schema is an XML document, unlike DTD which has its own unique syntax. For developers, you don't need to know both syntaxes to write a well-formed XML document. For developing XML parsers, since XML Schema is also XML syntax, it is more convenient to implement and support. At the same time, XML Schema inherits the extensible advantages of XML.

2. Define the data type. In a DTD file, data can only be declared as string type or sub-elements of string type, such as PCDATA, CDATA, ID, etc. In XML Schema, you can define the same rich data types as Programming languages, such as integers, Floating point types, Boolean types, date types, etc. The benefits of this are obvious. When you write a program to use an integer data, if it is defined with DTD, you must convert it from character type to integer type, and XML Schema can be directly defined as Integer type.

3. XML Schema is an open model. For example, the following XML document:

<item>
  <name>TG/DTLatte</name>
  <quantity>1</quantity>
  <price>2.00</price>
</item>
Copy after login

The following is its DTD and Schema description:

DTD:

<!ELEMENT name (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT item (name,quantity,price)>
Copy after login

schema

<ElementType name="name"/>
<ElementType name="quantity" dt:type="int"/>>
<ElementType name="price" dt:type="fixed.14.4"/>
<ElementType name="item" model="open">
<element type="name"/>
<element type="quantity"/>
<element type="price"/>
</ElementType>
Copy after login

When the above XML Adding a 10:21 PDT element to the document becomes:

<item xmlns:myItm="urn:myItems">
<name>TG/DT Latte</name>
<quantity>1</quantity>
<price>2.00</price>
<myItem:time>10:21 PDT</myItem:time>
</item>
Copy after login

The above DTD will cause a validation error, but the Schema will not.

Four.Integration of namespace. An XML document can only be described by one DTD document, but can be described by multiple XML Schema documents. The latter fully supports namespaces.

The above is the detailed content of A brief introduction to XML Schema. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source: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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template