See what "DTD" is in other dictionaries. Element Type Declaration


Document schema description

A DTD describes the document layout for a particular markup language through a set of declarations (parameter objects, elements, and attributes) that describe its class (or type) in terms of the syntactic constraints of that document. A DTD can also declare constructs that are always necessary to define the structure of a document, but can, however, affect the interpretation of certain documents.

Declaring parameter objects

A parameter object declaration defines a macro of a particular type that can be referenced and expanded somewhere in the DTD. These macros may not appear in the document itself, but only in the DTD. If a parameter object is referenced by the name of its DTD, it is expanded into a string that specifies the contents of that object.

The fontstyle parameter object contains a group of tags TT | I | B | BIG | SMALL.

"#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">

The inline parameter object contains text data and four more parameter objects fontstyle , phrase , special and formctrl .

Declaration of elements

Element declarations provide a list of allowed element names in a document, and also specify information regarding tags (whether they are required) and the content model for each element.

Various keywords and symbols define the content of an element:

  • EMPTY - empty content
  • ANY - any content
  • , - indicates the order
  • | - separation of alternatives
  • () - grouping
  • * - any number of elements (zero or more)
  • + - by at least one element (one or more)
  • ? - optional presence of an element (zero or one)
  • If not *, + or ? - there must be only one element

(DT|DD) +>

A DL element must contain one or more DT or DD elements in any order.

(%block;|SCRIPT) + -(FORM) >

A FORM element must contain one or more elements with a block parameter object or SCRIPT elements in any order, but it is not possible to contain another FORM element.

Defining Attributes

Each element in a DTD document can have a list of attributes associated with it. To do this, use the!ATTLIST directive, which specifies the name of the element to which the list of attributes can be mapped and the parameters of each attribute: its name, type and default properties.

For example:

name CDATA #REQUIRED>

This example defines a name attribute for the MAP element. It is mandatory.

There are these types of attributes:

  • CDATA (Character set of data) - the attribute value can be any character data
  • ID - the attribute value must be a unique identifier of the element
  • IDREF - the value of the element is a reference to the element by its ID
  • IDREFS - the same as IDREF, but with the ability to link not by one identifier, but by several
  • NMTOKEN - the attribute value can be a sequence of characters, somewhat similar to a name (hence the name - name token). This is a string that contains any combination of those characters that are allowed for XML names.
  • NMTOKENS - the attribute value is a list of values
  • ENTITY - the value is used to reference an external entity.
  • ENTITIES - allows you to specify a list of external entities, separated by spaces.
  • NOTATION - the attribute value can be one of the previously defined notations
  • NOTATIONS - allows you to specify a list of notations.
  • Listings and NOTATION-listings
  • ENUMERATION - specifies a list possible alternatives values.

There are the following default properties:

  1. IMPLIED - the attribute value is not required to be specified;
  2. REQUIRED - the attribute value must be specified;
  3. FIXED - the value of this attribute is specified as a constant in the DTD and cannot be changed in the document;
  4. some specific value that is used by default.

Association of a document with a specific DTD

To associate a document with a specific DTD, you must specify the Document Type Declaration element at the beginning of the document text.

Depending on the location of the DTD, the Document Type Declaration can be of two types:

  • Internal DTD subset

A set of DTD declarations is contained within the body of the document itself. For example:

]> ]>

  • External DTD subset

A set of DTD declarations is located in a separate text file with the extension .dtd In this case, a link to the file can be made through a public identifier and (or) through a system identifier. For example:

"http://www.w3.org/TR/html4/strict.dtd">

Example

The example is very simple XML DTD describing a list of people:

(person*) > (name, birthdate?, gender?, socialsecuritynumber?) > (#PCDATA) > (#PCDATA) > (#PCDATA) >

Starting from the first line:

  1. Element Contains any number of elements Sign<*>means that 0, 1 or more elements are possible Inside an element .
  2. Element Contains elements , , And . Signmeans the element is optional. Element does not contain, which means that the element must contain element .
  3. Element contains data.
  4. Element contains data.
  5. Element contains data.
  6. Element contains data.

An example XML document using this DTD:

> > > Fred Bloggs > > 27/11/2008> > Male > > 1234567890> > >

see also


Wikimedia Foundation. 2010.

See what "DTD" is in other dictionaries:

    DTD- , die in einer ASCII Datei (ASCII) abgelegte Beschreibung der Struktur von Dokumenten, welche alle vom selben Typ sind. Eine DTD wird nach den Regeln der international anerkannten… … Universal-Lexikon

    DTD- may stand for: Contents 1 Media 2 Music 3 Sports 4 Technologies 4.1 Computing ... Wikipedia

    DTD- steht für: Inhaltsverzeichnis 1 Medien 2 Music 3 Technologien 3.1 Computer 3.1.1 Spiele … Deutsch Wikipedia

    Dtd- steht für: Darwin Digital Television, eine australische Fernsehstation Delta Tau Delta, eine US amerikanische Studentenorganization Document Type Definition, siehe Dokumenttypdefinition … Deutsch Wikipedia

    DTD- (dē tē dēʹ) n. A set of rules for marking up a document in SGML. * * * …Universalium

    DTD- (document type definition) specification written in the Standard Generalized Markup Language and containing information about the format of a particular document (Computers) … English contemporary dictionary

In this chapter, we will discuss about DTD attributes. The attribute gives more information about an element, or more precisely it defines a property of the element. An XML attribute is always in the form of an im-value pair. An element can have any number of unique attributes.

An attribute declaration is very similar to element declarations in many ways except for one; Instead of declaring allowed content for elements, you declare a list of allowed attributes for each element. These lists are called by the ATTLIST declaration.

Syntax

The basic syntax for declaring DTD attributes is as follows:

In the above syntax

    Start DTD attributes withKeyword ATTLIST if the element contains an attribute.

    element-name specifies the name of the element to which the attribute is applied.

    attribute-name specifies the name of the attribute that is included with the name element.

    attribute-type defines the type of attributes. We will discuss more on this in the following sections.

    attribute with value takes a fixed value that the attributes must specify. We will discuss more on this in the following sections.

Example

Below is a simple example for declaring an attribute in a DTD:

]>

Tanmay Patil

Let's go through the above code:

    Start with an XML declaration with the following statement:

    Immediately after the XML header is a document type declaration, commonly called DOCTYPE:

    DOCTYPE tells the parser that the DTD is associated with this XML document. The DOCTYPE declaration has an exclamation mark (!) at the beginning of the element name.

    Following the DTD body. Here we declared the element and attribute:

Identification attribute for name element is defined as:

Here's the attribute type CDATA and its meaning #REQUIRED.

Attribute declaration rules

    All attributes used in an XML document must be declared in a document type definition (DTD) using an Attribute-List declaration

    Attributes can only appear in start or empty tags.

    The ATTLIST keyword must be at the top - case

    No double attribute names will be allowed within the attribute list for a given element.

Attribute types

By declaring attributes, you can specify how the handler should adjust the data that appears in the value. We can classify attribute type within three main categories:

    String type

    Types of Tokenized

    Types listed

The following table provides a summary of the different attribute types:

Type Description
CDATA CDATA character data (text and no price increase). String attribute type.
Identification This is a unique attribute designator. It should not appear more than once. Attribute type Tokenized.
IDREF It is used to reference the identity of another element. It is used to establish a connection between elements. Attribute type Tokenized.
IDREFS It is used to reference multiple ID. Attribute type Tokenized.
REALITY It represents external reality in the document. Attribute type Tokenized.
REALITY It represents a list of external realities in a document. Attribute type Tokenized.
NMTOKEN It is similar to CDATA and the value attribute consists of a valid XML name. Attribute type Tokenized.
NMTOKENS It is similar to CDATA and the value attribute consists of a list of a valid XML name. Attribute type Tokenized.
NOTATION The element will be referenced to the declared notation in the DTD document. Enumerated attribute type.
Designation It allows you to define a specific list of values ​​where one of the values ​​must match. Enumerated attribute type.

Declaring an attribute with a value

Within each attribute declaration, you must define how the value will appear in the document. You can define if attribute: then

    can have default value

    can have a fixed value

  • implies

Automatically accepted values

It contains the default value. Values ​​can be enclosed in single quotes (") or double quotes (")

Syntax

Following value syntax:

where the default values ​​are meaning a specific attribute with a value.

Example

Following is a simple example of an attribute declaration with an automatically accepted value:

]>

Tanmay Patil

In this example we have an element name With ID card attribute whose automatically accepted value 0 . The auto-assumed value is contained within the double quotations.

FIXED values

The #FIXED keyword to follow a fixed value is used when you want to specify that an attribute with a value is constant and cannot be changed. The general use of fixed attributes defines version numbers.

Syntax

Following is the fixed value syntax:

where #FIXED is a specific attribute with a value.

Example

The following is a simple example of an attribute declaration with a FIXED value:

]>

In this example we have used the #FIXED keyword where it indicates that the value "tutorialspoint" is the only value for name attribute element. If we try to change an attribute with a value after this, it gives an error.

Following invalid DTD:

]>

we are a free online teaching faculty

REQUIRED values

When you want to specify that an attribute is required, use the #REQUIRED keyword.

Syntax

Following the #REQUIRED syntax:

where #REQUIRED is a specific attribute type.

Example

Following is a simple example of a DTD attribute declaration with the #REQUIRED keyword:

]>

Tanmay Patil

In this example, we used the #REQUIRED keyword to determine that identification attribute must be provided for name element- name

IMPLIED meanings

When declaring attributes you must always specify a value declaration. If the attribute you declare has no default value, has no fixed value, and is not required, then you must declare that attribute as implied. The keyword #IMPLIED is used to define the attribute as implied.

Syntax

Following the #IMPLIED syntax:

where #IMPLIED is a specific attribute type.

Example

Following a simple example #IMPLIED

]>

In this example we used the keyword #IMPLIED as we don't want to specify any attributes to be included in name element. It's optional.

IN XML- documents DTD defines a set of valid elements, identifies elements that may be contained within other elements, and defines valid attributes for each of them. Syntax DTD is very unique and additional efforts are required from the author-developer when creating such documents (complexity DTD is one of the reasons that the use SGML, requiring definition DTD for any document, is not as widespread as, for example, HTML). As already noted, in XML use DTD not necessary - documents created without these rules will be processed correctly by the parser program if they satisfy the basic syntax requirements XML. However, control over the types of elements and the correctness of the relationships between them in this case will rest entirely with the author of the document. Until the grammar of our new language is described, only we will be able to use it, and for this we will be forced to use specially developed software, and not universal parser programs.

IN DTD For XML The following types of rules are used: rules for elements and their attributes, descriptions of categories (macro definitions), descriptions of binary data formats. All of them describe the basic constructs of the language - elements, attributes, symbolic constants, external binary data files.

In order to use DTD in our document, we can either describe it in an external file and in the description DTD simply provide a link to this file or select an area directly inside the document itself in which to define the necessary rules. In the first case, the document specifies the name of the file containing DTD- descriptions:

...

Inside the document, DTD declarations are included as follows:

... ... ]> ...

In the event that internal and external descriptions are used simultaneously, the analyzer program will first consider the internal ones, i.e. their priority is higher. When checking a document XML- the processor first looks for DTD inside the document. If the rules inside the document are not defined and the attribute is not set standalone="yes" , then the program will load the specified external file and the rules contained in it will be read from there. If the attribute standalone has the meaning " yes", then the use of external DTD descriptions will be prohibited.

Element Definition

Element in DTD defined using a descriptor! ELEMENT, which specifies the name of the element and the structure of its contents.

For example, for an element the following rule can be defined:

Keyword ELEMENT indicates that this instruction will describe an element XML. Inside this instruction the name of the element is specified (flower) and the type of its content.

In the element definition, we first specify the element name (flower), and then its content model - determining what other elements or data types may occur within it. In this case, the contents of the flower element will be determined using a special marker PCDATA(which means parseable character data - any information that the analyzer program can work with). There are two more statements that define the content type: EMPTY,ANY. The first indicates that the element should be empty (for example, ), the second is that the contents of the element are not specifically described.

The sequence of child objects for the current element is specified as a comma-separated list of element names. In this case, in order to indicate the number of repetitions of inclusions of these elements, the symbols +, *, ? :

This example specifies that inside an element elements must be defined title, author And table-of-contents, and the element title is a required element and can only appear once, the author element can appear multiple times, and the table-of-contents is optional, i.e. may be missing. If there are several possible options for the content of a defined element, they should be separated using the symbol "|" :

Symbol * in this example indicates that the defined sequence of internal elements may be repeated several times or not used at all.

If the element definition specifies "mixed" content, i.e. text data or a set of elements, you must first specify PCDATA and then separated by the symbol "|" list of elements.

Example of correct XML- document:

]> ...
Marks avenue
12-12-12 46-23-62 [email protected]

Defining Attributes

Element attribute lists are defined using a keyword! ATTLIST. Inside it, the names of the attributes, the types of their values ​​and additional parameters are specified. For example, for an element

The following attributes can be defined:

In this example, for the element article three attributes are defined: id, about And type, which have types ID(identifier), CDATA and a list of possible values, respectively. There are a total of six possible attribute value types:

  • CDATA- the contents of the document can be any character data
  • ID- defines a unique identifier of an element in a document
  • IDREF(IDREFS) - indicates that the attribute value should be the name (or several such names, separated by spaces in the second case) of the unique identifier of the element defined in this document
  • ENTITY(ENTITIES) - the attribute value must be a title (or a list of titles, if used ENTITIES) component (macro definition) defined in the document
  • NMTOKEN (NMTOKENS) - the content of the element can only be one single word (i.e. this parameter is a limited option CDATA)
  • List of valid values ​​- defines a list of values ​​that this attribute can have.

You can also use the following parameters in an attribute definition:

  • #REQUIRED- defines a required attribute that must be set in all elements of this type
  • #IMPLIED- the attribute is optional
  • #FIXED“value” - indicates that the attribute must have only the specified value, however, the attribute definition itself is not mandatory, but during the parsing process its value will in any case be passed to the analyzer program
  • Value - sets the default value of the attribute

Defining Components (Macro Definitions)

Component (entity) represents definitions whose contents can be reused in a document. In other programming languages, similar elements are called macrodefinitions. Are being created DTD- components using instructions !ENTITY:

Analyzer program, looking first at the contents of the area DTD- definitions, will process this instruction and will use the contents during further parsing of the document DTD- the component in the place where its name will appear. Those. Now in the document we can use the expression &hello; , which will be replaced with the line " We are happy to greet you"

In general, inside DTD You can define three types of macro definitions:

Internal macro definitions - are designed to define a string constant; with their help, you can organize links to frequently changed information, making the document more readable. Internal components are included in a document using an ampersand &

IN XML There are five predefined internal symbolic constants:

  • < - symbol "<"
  • > - symbol ">"
  • & - symbol "&"
  • " - apostrophe symbol """
  • " - double quote character """

External macro definitions - point to the contents of an external file, and this content can be either text or binary data. In the first case, text strings will be inserted where the macro is used, in the second - binary data that is not considered by the analyzer and is used by external programs

Rule Macro Definitions - parameter macro definitions can only be used within the DTD area and are indicated by a special symbol % , inserted before the macro name. In this case, the contents of the component will be placed directly in the text DTD- rules

For example, for the following document fragment:

You can use a shorter form:

Macros are often used to describe parameters in attribute rules. In this case, it becomes possible to use the same attribute definitions for different elements:

Data typing

Quite often when creating XML- the element developer needs to determine what type of data can be used as its content. Those. if we define an element10.10.98 , then we want to be sure that in the document at this place there will be a string representing a date, and not a number or an arbitrary sequence of characters. Using data typing, you can create elements whose values ​​can be used, for example, as parameters SQL- requests. In this case, the client program must know what data type the current value of the element belongs to and, if it matches, generates SQL-request.

If a verifier is used as a client-side program XML-processor, then information about the type can be transmitted using an element specially created for this attribute that has the corresponding DTD- definition. During the parsing process, the parser will pass the value of this attribute to the client application, which can use this information as expected. For example, to specify that the content of an element should be a long integer, you could use the following DTD- definition:

By setting the attribute to its default value LONG and defining it as FIXED, we have thereby allowed the client program to obtain the necessary information about the content type of this element, and now it can independently determine whether the content type matches the one specified in DTD- definition.

Here's an example XML- a document in which several elements with different data types are defined and used:

... 5 2 32.5 true 18346 34 rub. 28 k. ...

As can be seen from the example, the mechanism for creating document elements has not changed at all. All the information necessary to check data types is included in the definitions of the elements inside the block DTD.

In conclusion, I would like to note that DTD provides us with a very convenient mechanism for monitoring the contents of the document. Today, almost all Internet document viewing programs use DTD-rules. However, this is far from the only way to check the correctness of a document. Currently in W3 The consortium is considering a new standard for a language for describing the structure of documents, called data schemas. The next section is devoted to working with them.

This is the next article in the series “XML Basics” and in it we will look at the basics of describing the structure of XML data using DTDs. This is a fairly old way of describing the structure of XML documents, but it is still used, so we will still look at it.

I would also like to point out that this is a great way to show how XML checks document content, grammar, etc. We will look at a newer and more advanced way of describing the structure of XML documents using XML Schema technology in the next article, but for now let’s move on directly to studying the XML DTD.

In this article we will look at several important points at once. This is what an XML DTD is and what it is needed for, let's talk about the disadvantages of DTD, and also learn how to independently compose your own DTD for validating XML documents. All this, as usual, will be presented step by step, as briefly and clearly as possible in order to save your time.

So, let's begin.

What is a DTD in XML and why is it needed?

In short, a DTD in XML is used to check the grammar of a document and its conformance to a standard (one that the developer or you came up with). This allows the parser (processor) to determine at the processing stage whether the document meets our requirements. That is, the XML document is validated.

The need to check the grammar of XML documents is as follows:

  • The XML document may not be intended for your system.
  • The XML document may contain incorrect data.
  • The XML document may contain errors in the structure ().

So, we figured out what an XML DTD is and why it is needed. Now let's briefly look at the disadvantages of DTDs, and then move on to the process of creating DTD files for validating XML documents.

Disadvantages of XML DTD

  • Language syntax different from XML. This causes many problems, such as encoding problems or the inability to track errors.
  • No data type checking. There is only one type in DTD - string.
  • There is no DTD. You cannot match two or more DTD descriptions to a document.

This was a short list of DTD shortcomings that have been successfully corrected in XML schemas, which we will talk about in future articles.

Declaring elements, attributes and entities in a DTD. Modifiers “*”, “?”, “+”

Special declarations and modifiers are used to declare elements, attributes, and entities in a DTD. To understand everything in detail, let's first look at the theoretical information, and then in the second part of the article we will move on to practical examples.

Defining an XML Element and a Sequence of XML Elements

The book element contains one title, author, price, and description elements.

Element Alternatives

The pricelist element contains the elements title, price and one of three elements to choose from – author, company or sample.

Empty elements

The none element must be empty.

Attribute Declaration

The pricelist element can contain two attributes - an id attribute and a name attribute. In this case, the id attribute is required, since #REQUIRED is specified, and the name attribute is optional (#IMPLIED is specified). In turn, CDATA indicates to the handler that there is no need to parse the contents of the attributes.

Defining Entities

If the entity “” is encountered, then “Dmitry Denisov” will be automatically substituted instead.

Modifiers (explain repetitions of elements)

* - zero or many.
? – zero or one.
+ - one or many.

The books element can contain one or more book elements.

Now let's look at what this all looks like with more practical examples.

Creating a DTD file for validating an XML document using the example of a book price list

Let us have the same price list of books that we use for examples in almost every article about XML. The XML document itself will look something like this.

Book 1 &myname; Price 1 Description

Of course, the above example is not the ultimate dream, but it will do as an example. As you can see from the example, we have a root element pricelist, which contains nested book elements. Inside the book elements there are title, author, price and possibly description elements, which may contain some text data.

To validate this price list, we can use the following DTD document.

Now let's look at everything in more detail.

  • — we declare the root element books and indicate in parentheses what it can contain. In this case, it can contain one or more book elements (the plus sign means one or more, see above).
  • — define the book element. The book element can contain one title element, one or more author elements (plus sign), one price element, and one or no description elements (question mark).
  • — define the title element. We specify #PCDATA as the content of the element. This means that the parser is required to parse what is inside this element.
  • Similarly, we define the elements author, price, description.
  • — we define the essence. First we write the entity itself, and then in quotes what will be displayed in its place. By default, only 3 entities are defined in XML. This is more (">" -<), меньше («<» — >) and ampersand (“&” - &). If you wish, you can create an unlimited number of entities using this method. The meanings can be not only words, but also entire sentences of significant length.
Connecting DTD for validating XML documents

Declarative method

This method is very rarely used, since its essence is to create self-sufficient documents. That is, the document will immediately contain both DTD and XML. The following construct is used to add a DTD to XML.

where instead of DOCUMENT we indicate the root element of the XML document.

For clarity, let's look at an example of a ready-made self-sufficient document with a declarative way to include a DTD.

]>

External DTD definition - connecting a DTD document

The essence of this method is to connect a DTD file to an XML document using the following construction.

where DOCUMENT – we indicate the root element of the XML document.
file.dtd – link to the DTD file.

For clarity, consider the following example.

XML document

This concludes this article. We looked at all the main points when working with XML DTD and, I hope, I was able to explain everything clearly. If you don't want to miss other XML and XSLT tutorials, I recommend subscribing to the newsletter using the form below.

That's all. Good luck and success in learning XML!

Use XML Schemas instead of DTDs to define the structure of XML documents

XML Schema is more powerful than DTD. To illustrate the benefits of using the XML Schema engine, the first three listings compare different ways of representing elements. The following is an excerpt from the XML document. B shows the two elements declared in DTD syntax, and B shows the syntax corresponding to the XML schema. Note that the syntax in Listing 3 is similar to XML syntax. When using a schema, the validating parser can check whether the InvoiceNo element is a positive integer, and whether the ProductID consists of a given set of characters (six numbers and one letter from A to Z). The parser processing the DTD definition can only confirm that the given elements are strings.

Listing 1: XML document fragment
123456789 J123456
Listing 2: DTD fragment describing the elements from Listing 1
Listing 3: XML Schema fragment describing the elements from Listing 1

Using Namespaces in XML Schema

DTD Limitations

Although DTDs have served SGML and HTML developers as a mechanism for describing structured information for 20 years, DTDs have some limitations compared to XML schemas.

According to the DTD, an element can be represented in one of three ways:

  • Text string
  • Text string mixed with another child element
  • Set of children

DTDs do not have XML syntax and offer only limited support for types and namespaces.

When working together, one party may process the other parties' documents, and different parties may represent their data elements differently. Moreover, in a separate document, they may need to independently reference elements with the same name created by different parties. Using XML Schema allows definitions with the same name to be differentiated by defining different namespaces.

Such an XML schema defines a set of new names, such as the names of elements, types, attributes, and attribute groups, whose definitions and declarations are described in the schema. The names are defined as InvoiceNo , ProductID and ProductCode .

The names defined in the schema belong to the so-called target namespace. The namespace itself is a fixed, arbitrary name that must follow URL syntax. For example, the namespace for the schema presented in , can be set as follows: http://www.SampleStore.com/Account.

The syntax for declaring a namespace can sometimes be confusing. The declaration starts with http:// , but it does not link to the schema file. In fact, the link http://www.SampleStore.com/Account does not lead to any file at all, but only to the assigned name.

Definitions and declarations in a schema can refer to names that may belong to other namespaces. In this article we refer to such namespaces as: original namespaces. Each schema can define one target namespace and possibly multiple source namespaces. In general, each name in a given schema belongs to a certain namespace. Namespace names can be quite long, but they can be shortened using the xmlns declaration syntax in the XML schema document. All these concepts are illustrated in.

Listing 4: Destination and source namespaces

In the XML schema represented with , the targetNamespace namespace is http://www.SampleStore.com/Account and contains the names InvoiceNo , ProductID , and ProductCode . The names schema , element , simpleType , pattern , string , and positive-integer belong to the original namespace http://www.w3.org/1999/XMLSchema , which is abbreviated as xsd by declaring xmlns . There is nothing special about the xsd alias; you can choose another name. For convenience and simplicity, in the remainder of the article we will use the xsd prefix to refer to the http://www.w3.org/1999/XMLSchema namespace, omitting the xsd qualification in some parts of the code. In our example, targetNamespace is also one of the original namespaces, since the ProductCode name is used in the definition of other names.

Figure 1: Namespaces for Listing 4
Listing 5: Multiple source namespaces, namespace import

Defining Elements

Defining an element consists of defining its name and content model. In an XML schema, an element's content model is determined by its type. Therefore, elements in an XML document can only have values ​​that match the types defined in its schema.

Simple types

The XML Schema specification defines several simple types for values, as shown in Table 2—predefined simple value types.

The element type can be simple or complex (complex). Element simple type cannot contain other elements or attributes. A complex type can have the effect of embedding elements within other elements, or can associate attributes with an element. Up to this point, we have only used examples with simple user-defined types (see ProductCode). The XML Schema specification also includes predefined simple types (see box). Predefined simple type Restricts values ​​to their underlying type. For example, the value of the predefined simple type ProductCode is a subset of the values basic type string .

Simple, non-nested elements have a simple type

An element that contains no attributes or other elements may be assigned a simple type, predefined or user-defined, such as string, integer, decimal, time, ProductCode, etc.

Listing 7: Some simple element types

Elements with attributes must be of complex type

Now let's try to add to simple element price from the currency attribute. You won't be able to do this because an element of a simple type cannot have attributes. If you want to add an attribute, you need to define price as an element of complex type. In the example from , we define the so-called anonymous type, in which the complex type is not given an explicit name. In other words, the name attribute of the complexType element is undefined.

Listing 8: Complex type element

Elements containing nested elements must be of complex type

In an XML document, other elements can be nested within an element. This requirement is expressed directly in the DTD. An XML schema instead defines an element and its type, which can include declarations of other elements and attributes. An example is given in.

Table 1: Comparison of complex data types in DTD and XML Schema

XML document
Cool XML <Title> <Author>Cool Guy</Author> </Book> </span><h5>DTD</h5><span> <!ELEMENT Book (Title, Author)> <!ELEMENT Title (#PCDATA)> <!ELEMENT Author (#PCDATA)> </span><h5>XML Schema</h5><span> <element name="Book" type="BookType"/> <complexType name="BookType"> <element name="Title" type="string"/> <element name="Author" type="string"/> </complexType> </span><h5>Listing 10: Hiding BookType as a local type</h5><span> <element name="Title" type="string"/> <element name="Author" type="string"/> <element name="Book"> <complexType> <element ref="Title"/> <element ref="Author"/> </complexType> </element> </span><h2>Expressing complex constraints on elements</h2><p>An XML Schema offers more flexibility than a DTD in expressing constraints on an element's content model. At the simplest level, such as in a DTD, you can associate attributes with an element, and also specify that a sequence of only one (1), zero or more (*), or one or more (+) elements of a given element may appear in it. set of elements. You can express additional constraints in an XML schema using, for example, the minOccurs and maxOccurs attributes on the element element and the choice , group , and all elements.</p><h5>Listing 11: Constraint expression for element types</h5><span> <element name="Title" type="string"/> <element name="Author" type="string"/> <element name="Book"> <complexType> <element ref="Title"/> <element ref="Author"/> </complexType> </element> </span><p>The Title tag is optional in relation to the Book tag (the same rule can be set in the DTD). However, it also says that the Book element must have at least one and no more than two Author elements. The default value of the element tag's minOccurs and maxOccurs attributes is 1. The choice element indicates that only one of the specified child elements can appear. Another all element specifies that all child elements can appear only once, together and in any order, or not appear at all. It is announced that both <a href="https://gtavrl.ru/en/v-pamyat-o-keywords-dlya-chego-nuzhen-meta-teg-keywords-pochemu-on-ne-rabotaet/">Title tag</a> and Author must appear in the Book in any order, or not at all. Such restrictions are difficult to express using DTD.</p><h5>Listing 12: Indicating that an element must have all types defined</h5><span> <xsd:element name="Title" type="string"/> <xsd:element name="Author" type="string"/> <xsd:element name="Book"> <xsd:complexType> <xsd:all> <xsd:element ref="Tile"/> <xsd:element ref="Author"/> </xsd:all> </xsd:complexType> </xsd:element> </span><h2>Summarizing</h2><p>IN <a href="https://gtavrl.ru/en/poisk-dokumentov-i-dannyh-v-internet-sekrety-poiska-v-internet-i/">this document</a> we revealed with the help <a href="https://gtavrl.ru/en/kak-sostavit-semanticheskoe-yadro-stati-prostoi-primer-sostavleniya/">simple examples</a> The most fundamental concepts needed to define the structure of elements using XML Schema. Many other powerful mechanisms are also available:</p><ul><li>XML Schema provides comprehensive support for type inheritance, allowing you to reuse previously defined structures. This use is called <i>aspects</i>. You can infer new types that represent a smaller subset of the values ​​of other types, for example, to define a subset by an enumeration, a range, or a pattern match. In one of the examples in this article, the ProductCode type was defined using the pattern aspect. In a subtype, you can also add new elements and attributes to the base type.</li><li>Several mechanisms to control <a href="https://gtavrl.ru/en/bluescreenview-kak-polzovatsya-dlya-opredeleniya-prichiny-bsod-obshchie-rekomendacii-po/">general definition</a> subtype or replace it in a specific document. For example, you can specify that the InvoiceType type (invoice number type) cannot contain subtypes, that is, no one will be able to determine <a href="https://gtavrl.ru/en/skachat-flesh-pleer-novoi-versii-v-novoi-versii/">new version</a> InvoiceType. You can also specify that there cannot be subtype substitutions in a particular context for the ProductCode type.</li><li>In addition to using subtypes, it is possible to define equivalent types, that is, the value of one type can be replaced by the value of another.</li><li>XML Schema provides a mechanism for replacing an element or type by declaring it abstract.</li><li>For added convenience, you can define and name groups of attributes or elements. This allows them to be reused in subsequent calls.</li><li>The XML schema provides three elements—appInfo, documentation, and annotation—for the use of comments by both humans (documentation) and applications (appInfo)</li><li>You can express unique constraints based on specific attributes of child elements.</li> </ul><p>Additional information on XML schemas can be obtained from the documentation on the W3C sites (See) and dW XML zone. Now that the XML Schema specification has been confirmed as a candidate for a W3C recommendation, you can confidently use it to its full potential.</p> <script>document.write("<img style='display:none;' src='//counter.yadro.ru/hit;artfast_after?t44.1;r"+ escape(document.referrer)+((typeof(screen)=="undefined")?"": ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth? screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";h"+escape(document.title.substring(0,150))+ ";"+Math.random()+ "border='0' width='1' height='1' loading=lazy loading=lazy>");</script> </div><div class="clear"></div> <script type="text/javascript"> document.getElementById('hc_full_comments').innerHTML = ''; </script><br /><br /><noindex><p align="center"><center> <div id="meta_news_block1111" style="text-align: center;"></div></center> </p> <br /><br /> <p align="center"> </p> </noindex> </div> </div> <div id="sidebar"> <div class="clear"></div><br /> <h2 class="front" style="margin:15px 0 5px 0">Popular articles</h2> <div class="tabcont"> <ol> <li><a href="https://gtavrl.ru/en/chto-nado-nazhat-chtoby-istoriya-ne-sohranyalas-kak-sdelat-chtoby-ne-sohranyalas-istoriya-kak-udalit/">How can I prevent history from being saved?</a></li> <li><a href="https://gtavrl.ru/en/fotoredaktor-sketch-karikatury-delaem-karikaturu-iz-fotografii-v/">Making a caricature from a photograph in Photoshop</a></li> <li><a href="https://gtavrl.ru/en/otklyuchit-fonovye-prilozheniya-android-apk-editor-uvelichivaem/">Increasing smartphone performance</a></li> <li><a href="https://gtavrl.ru/en/vyhod-samsung-galaxy-note-5-samsung-galaxy-note5---tehnicheskie-harakteristiki-informaciya-o/">Samsung Galaxy Note5 - Specifications</a></li> <li><a href="https://gtavrl.ru/en/kak-bystro-uznat-svoi-nomer-mts-kak-bystro-uznat-svoi-nomer-mts-komanda/">How to quickly find out your MTS number Team at MTS find out your phone number</a></li> </ol> </div> <h2 class="front" style="margin:15px 0 5px 0">Latest articles</h2> <div class="tabcont"> <ol> <li><a href="https://gtavrl.ru/en/kak-popolnit-schet-drugomu-abonentu-bilain-so-svoego-balansa/">Transferring money between Beeline subscribers: available ways to Top up from your Beeline balance</a></li> <li><a href="https://gtavrl.ru/en/tarif-moi-bezlimit-tele2-opisanie-podklyuchenie-i-stoimost-opcii/">Mobile unlimited options on Tele2 What is unlimited Internet on Tele2</a></li> <li><a href="https://gtavrl.ru/en/pochemu-telefon-otklyuchilsya-i-bolshe-ne-vklyuchaetsya-chto-delat/">What to do if the phone does not turn on?</a></li> <li><a href="https://gtavrl.ru/en/test-draiv-golosovogo-pomoshchnika-alisa-ot-yandeksa-golosovoi-pomoshchnik-alisa/">Voice assistant Alice: download for Android Yandex voice assistant Alice download for Android</a></li> <li><a href="https://gtavrl.ru/en/skachat-prilozhenie-russko-angliiskii-perevodchik-besplatnye/">Free programs for Windows download for free</a></li> <li><a href="https://gtavrl.ru/en/wot-kak-napisat-soobshchenie-kak-napisat-soobshchenie-v-world-of-tanks-wot-nekotorye/">How to write a message in World of Tanks (WoT)?</a></li> <li><a href="https://gtavrl.ru/en/prikolnye-kartinki-na-avu-pacanu-prikolnye-kartinki-na-avu/">Cool pictures for a boy's avatar Avatars for VKontakte guys are cool</a></li> </ol> </div> <div class="widget" id="ajdg_grpwidgets-3"> <div class="g g-9"> <div class="g-single a-27"> <script> jQuery(function() { window.onscroll = function() { height_scroll = jQuery(document).scrollTop(); height = jQuery(document).height(); height50 = height / 2; if (height_scroll >= height50) { jQuery("#site-code-block-22").fadeIn(1200); document.getElementById('site-code-block-22').style.display = 'block'; jQuery("#site-code-block-23").fadeOut(1200); document.getElementById('site-code-block-23').style.display = 'none'; } else { jQuery("#site-code-block-22").fadeOut(1200); document.getElementById('site-code-block-22').style.display = 'none'; document.getElementById('site-code-block-23').style.display = 'block'; jQuery("#site-code-block-23").fadeIn(1200); } }; }); </script> <div class="site-code-block prma-count" data-rel="cb_23" id="site-code-block-23" style=""> </div> <div class="site-code-block prma-count" data-rel="cb_22" id="site-code-block-22" style=""> </div> </div> </div> </div> <div class="clear"></div> <br /> <center> <div style="color: #333333; font-size: 11px;"> </div> </center> <div class="clear"></div> </div> <div class="clear"></div> </div> </div> </div>  <br /><br /> <div id="footeri"> <div id="footer"> <div class="footer-sec"> <h6>Sections</h6> <ul> <li><a href="https://gtavrl.ru/en/category/youtube/">Youtube</a></li> <li><a href="https://gtavrl.ru/en/category/facebook/">Facebook</a></li> <li><a href="https://gtavrl.ru/en/category/twitter/">Twitter</a></li> <li><a href="https://gtavrl.ru/en/category/tips/">Adviсe</a></li> <li><a href="https://gtavrl.ru/en/category/useful-tips/">Useful tips</a></li> <br /> </ul> </div> <div class="footer-sec"> <h6>Pages</h6> <ul> <li><a href="">about the project</a></li> <noindex> <li><a href="" >RSS news</a></li> </noindex> </ul><br /><br /><br /> <h6>Special projects</h6> <ul> <li><a href="https://gtavrl.ru/en/feedback/">Connect with us</a></li> </ul> </div> <div id="footer-top"> <h6>Contacts</h6> <ul> <li><a href="">Advertising on the website</a></li> <li><a href="https://gtavrl.ru/en/feedback/">Contacts</a></li> </div> <div class="clear"></div> </div></div> <div id="bottom"><div class="foot_col1">2024 <a href="https://gtavrl.ru/en/">gtavrl.ru</a>. </div> <script type="text/javascript">var addthis_config = { "data_track_addressbar":true,"pubid": "ra-58b68bb0f1371607"} ;addthis_config.data_track_addressbar = false;addthis_config.data_track_clickback = false;</script> <script type='text/javascript'> var flag_hide = 0; function hide_direct() { flag_hide = 1; jQuery('#rek_mob_fixed').slideToggle( 'slow' ); var date = new Date(); var expires_hour = 21600000; date.setTime(date.getTime()+expires_hour); showSocial(); Cookies.set('advp_show_me', '1', { expires: date, path: '/'} ); } ; jQuery(function(f){ var element = f('#rek_mob_fixed'); element.delay(8000); f(window).scroll(function(){ if (flag_hide == 0){ var offset_element_for_hide = jQuery('#before_footer').val(); if (offset_element_for_hide != null) { offset_element_for_hide = jQuery('#before_footer'); offset_element_for_hide = jQuery(offset_element_for_hide).offset().top - jQuery(window).height(); } else { offset_element_for_hide = jQuery(document).height(); } //Если рекламный блок более 1000px по ширине, устанавливай фикс. ширину 1000px if (jQuery('#rek_mob_fixed_block').actual('width') >1000) { jQuery('#rek_mob_fixed_block').css({ 'max-width':'1000px'} ); } if(f(this).scrollTop() > 500){ element.fadeIn(0); } if(f(this).scrollTop() < 500 || f(this).scrollTop() > offset_element_for_hide ){ element.fadeOut(0) } if(f(this).scrollTop() + f(this).height() >= f(document).height() && flag_hide == 0 && jQuery('#rek_mob_fixed').is(':visible')) { jQuery('#rek_mob_fixed').slideToggle(100); } } } ); } ); function showSocial(){ if(flag_hide == 1 ) jQuery('#footer-share').slideToggle('slow'); } </script><div id="wondergridgallerylightbox_options" data-skinsfoldername="skins/default/" data-jsfolder="/wp-content/plugins/modesco-wonderplugin-gridgallery/engine/" style="display:none;"></div> <script type='text/javascript' src='https://gtavrl.ru/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=4.9.2'></script> <script type='text/javascript' src='https://gtavrl.ru/wp-content/plugins/modesco-monica/script.min.js?ver=4.9.1'></script> <script type='text/javascript'> /* <![CDATA[ */ var tocplus = { "visibility_show":"\u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c","visibility_hide":"\u0441\u043a\u0440\u044b\u0442\u044c","width":"100%"} ; /* ]]> */ </script> <script type='text/javascript' src='https://gtavrl.ru/wp-content/plugins/modesco-table-of-contents-plus/front.js?ver=1404'></script> <script type='text/javascript' src='https://gtavrl.ru/wp-content/plugins/page-links-to/js/new-tab.min.js?ver=2.9.8'></script> <script type='text/javascript'> var q2w3_sidebar_options = new Array(); q2w3_sidebar_options[0] = { "sidebar" : "ads-sidebar", "margin_top" : 10, "margin_bottom" : 50, "stop_id" : "before_footer", "screen_max_width" : 0, "screen_max_height" : 0, "width_inherit" : false, "refresh_interval" : 1500, "window_load_hook" : false, "disable_mo_api" : false, "widgets" : ['ajdg_grpwidgets-3'] } ; </script> <script type='text/javascript' src='https://gtavrl.ru/wp-content/plugins/q2w3-fixed-widget/js/q2w3-fixed-widget.min.js?ver=5.0.4'></script> <script type='text/javascript' src='https://gtavrl.ru/wp-content/plugins/youtube-embed-plus/scripts/fitvids.min.js?ver=4.9.1'></script> <script type='text/javascript' src='/wp-includes/js/wp-embed.min.js?ver=4.9.1'></script> <script type="text/javascript"> var _hcwp = _hcwp || []; var _hcobj = { widget_id : 29264, widget : "Bloggerstream",selector: '.hc_counter_comments',platform:"wordpress", } ; _hcwp.push(_hcobj); (function() { if("HC_LOAD_INIT" in window)return; HC_LOAD_INIT = true; var lang = "ru"; var hcc = document.createElement("script"); hcc.type = "text/javascript"; hcc.async = true; hcc.src = ("https:" == document.location.protocol ? "https" : "http")+"://w.hypercomments.com/widget/hc/29264/"+lang+"/widget.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hcc, s.nextSibling); } )(); </script> </body> </div> </body> </html> <script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>