XML Document Type Definitions Extensible Markup Language ..., Slides of Chemistry

A vertical bar ( | ) is used to indicate one element or another. A DTD follows for a grocery store application. grocery.dtd. <!-- A document type definition ...

Typology: Slides

2022/2023

Uploaded on 02/28/2023

aasif
aasif 🇺🇸

4.9

(7)

218 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
XML Document Type Definitions
Extensible Markup Language (XML) has developed in a major way in the last few years. It has become
one of the most important means of exchanging information of all kinds on the Internet. And there are
now a number of different specialized versions of XML. These range from markup for chemistry
documents to a quick way to distribute news releases.
Specialized versions are accompanied by document type definitions (DTDs) and/or schema. Both provide
some information about the tags used in the field, but schema, being more recent, are more extensive.
However, we will begin with a look at DTDs.
Document Type Definitions
A DTD for an xml file is a list of elements (tags) used in the file, together with some information about
how they are defined. The document must have a single root node. This is followed by the children of
the root and either their children or data type. In a DTD there are only two data types, PCDATA (parsed
character data) or CDATA, unparsed character data. Most of the examples will use parsed character data.
A DTD also indicates how many times an element can occur in the file. The default is once. But most
files use the same tag names a number of times. The notation used is similar for that used in regular
expressions.
* means zero or more occurrences.
+ means one or more occurrences.
? means zero or one occurrence.
A DTD also allows for choice. A vertical bar ( | ) is used to indicate one element or another.
A DTD follows for a grocery store application.
grocery.dtd
<!-- A document type definition for grocery.xml. -->
<!ELEMENT grocery (heading+, fruit*, vegetables*, bakery*)>
<!-- The elements that have children. -->
<!ELEMENT heading (name, id, quantity, price)>
<!ELEMENT fruit (name, id, quantity, price)>
<!ELEMENT vegetables (name, id, quantity, price)>
<!ELEMENT bakery (name, id, quantity, price)>
<!-- Definition of the data types. -->
<!ELEMENT name (#PCDATA)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT price (#PCDATA)>
From this DTD you can see that the root element is <grocery>. This element has four different kinds of
children. There can be zero or one heading. The heading can be used in a table that displays the file. The
DTD also indicates that there can be zero or more fruit, vegetables, and bakery elements. But it also
mandates that all fruit elements come first, vegetable elements next, and bakery elements last.
A file that satisfies all these requirements follows:
pf3
pf4
pf5

Partial preview of the text

Download XML Document Type Definitions Extensible Markup Language ... and more Slides Chemistry in PDF only on Docsity!

XML Document Type Definitions

Extensible Markup Language (XML) has developed in a major way in the last few years. It has become one of the most important means of exchanging information of all kinds on the Internet. And there are now a number of different specialized versions of XML. These range from markup for chemistry documents to a quick way to distribute news releases.

Specialized versions are accompanied by document type definitions (DTDs) and/or schema. Both provide some information about the tags used in the field, but schema, being more recent, are more extensive. However, we will begin with a look at DTDs.

Document Type Definitions

A DTD for an xml file is a list of elements (tags) used in the file, together with some information about how they are defined. The document must have a single root node. This is followed by the children of the root and either their children or data type. In a DTD there are only two data types, PCDATA (parsed character data) or CDATA, unparsed character data. Most of the examples will use parsed character data.

A DTD also indicates how many times an element can occur in the file. The default is once. But most files use the same tag names a number of times. The notation used is similar for that used in regular expressions.

    • means zero or more occurrences.
    • means one or more occurrences. -? means zero or one occurrence. A DTD also allows for choice. A vertical bar ( | ) is used to indicate one element or another.

A DTD follows for a grocery store application.

grocery.dtd

From this DTD you can see that the root element is . This element has four different kinds of children. There can be zero or one heading. The heading can be used in a table that displays the file. The DTD also indicates that there can be zero or more fruit, vegetables, and bakery elements. But it also mandates that all fruit elements come first, vegetable elements next, and bakery elements last.

A file that satisfies all these requirements follows:

Name ID Quantity Price apples A123 25 1.25 pears P234 50 2.55 beans B345 10 .85 corn C456 60 .50 bread B567 15 2.30 cake C678 4 4.25

Some browsers will use this information to display the file while others will ignore it. Both Foxfire and Netscape version 7.2 understand the style sheet, while Internet Explorer version 6.0 does not.

The following style sheet will display the file in a table. grocery.css

/* Style sheet for address application. */ grocery { font-family: "Times New Roman", serif display: table; border-style: solid; border-width: thin; margin-left: 1.0cm; margin-top: 1.0cm; } heading, fruit, vegetables, bakery { display: table-row; } name, id, quantity, price { display: table-cell; border-style: solid; border-width: thin; padding: 0.3cm; text-align: center; }

If this style sheet is applied, the display looks like the following in Foxfire.

This style sheet says that the root element, grocery, should be displayed as a table. display: table; The other styles determine the font and table properties such as a solid, thin border and 1 cm margins.

The columns of the table are given by the next elements, heading, fruit, vegetables, and bakery. The style for these is display: table-row. This will display these elements as rows.

Finally the data elements, name, id, quantity, and price, will be displayed in the table cells. display: table-cell; The cell styles must also have instructions as to how the borders should appear.

There are many other applicable styles. W3Schools has an extensive list in their tutorial on CSS.

Attribute Lists in DTDs

XML tags may include attributes. These are name-value pairs such as width = "300". We have seen these in applet and image tags. They can be used in XML and are required in some places. An example might be the following xml file that contains information about students in a course. Each exam grade has a weight attribute to indicate how it should factor into the course grade.

Name Midterm Final Alice Lee 85 92 Barbara Smith 78 84 Cathy Jones 82 87