Download Document Type Definitions - Database Systems - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!
XML
Document Type Definitions
XML Schema
Well-Formed and Valid XML
- Well-Formed XML allows you to invent your own tags.
- Valid XML conforms to a certain DTD.
Tags
- Tags are normally matched pairs, as … .
- Unmatched tags also allowed, as
- Tags may be nested arbitrarily.
- XML tags are case-sensitive.
Example: Well-Formed XML
Joe’s Bar Bud 2.50 Miller 3.00 … 5
A NAME subelement
A BEER subelement
Root tag
Tags surrounding a BEER element
DTD Elements
- The description of an element consists of its name (tag), and a parenthesized description of any nested tags. - Includes order of subtags and their multiplicity.
- Leaves (text elements) have #PCDATA ( Parsed Character DATA ) in place of nested tags.
Example: DTD
]>
8
A BARS object has zero or more BAR’s nested within.
A BAR has one NAME and one or more BEER subobjects.
A BEER has a NAME and a NAME and PRICE are text. PRICE.
Example: Element Description
- A name is an optional title (e.g., “Prof.”), a first name, and a last name, in that order, or it is an IP address:
(TITLE?, FIRST, LAST) | IPADDR
)>
Use of DTD’s
- Set standalone = “no”.
- Either:
a) Include the DTD as a preamble of the XML document, or b) Follow DOCTYPE and the by SYSTEM and a path to the file where the DTD can be found.
Example: (b)
- Assume the BARS DTD is in file bar.dtd.
Joe’s Bar Bud 2.50 Miller 3.00 … 13
Get the DTD from the file bar.dtd
Attributes
- Opening tags in XML can have attributes.
- In a DTD,
declares attributes for element E , along with its datatype.
Example: Attribute Use
- In a document that allows BAR tags, we might see:
Homma’s Sapporo 5.00 ...
ID’s and IDREF’s
- Attributes can be pointers from one object to another. - Compare to HTML’s NAME = ”foo” and HREF = ”#foo”.
- Allows the structure of an XML document to be a general graph, rather than just a tree.
Creating IDREF’s
- To allow elements of type F to refer to another element with an ID attribute, give F an attribute of type IDREF.
- Or, let the attribute have type IDREFS, so the F -element can refer to any number of other elements.
Example: ID’s and IDREF’s
- A new BARS DTD includes both BAR and BEER subelements.
- BARS and BEERS have ID attributes name.
- BARS have SELLS subelements, consisting of a number (the price of one beer) and an IDREF theBeer leading to that beer.
- BEERS have attribute soldBy, which is an IDREFS leading to all the bars that sell it.