CH4 WEB Lecture
CH4 WEB Lecture
<City ZIP=“94608”>
Emeryville </City>
Attributesare used to attach
additional, secondary
information to an element.
Authoring XML
Documents
A basic XML document is an XML element
that can, but might not, include nested
XML elements.
Example:
<books>
<book isbn=“123”>
<title> Second Chance </title>
<author> Matthew Dunn </author>
</book>
</books>
XML Data Model:
Example
<BOOKS>
<book id=“123”
loc=“library”>
<author>Hull</author>
<title>California</title>
<year> 1995 </year>
</book>
<article id=“555”
ref=“123”>
<author>Su</author>
<title> Purdue</title>
</article>
Hull
</BOOKS>
XML Data Model: Example
<?xml version="1.0" encoding="ISO-8859-1"?>
<customer>
<firstname>Michael</firstname>
<lastname>Smith</lastname>
<gender>male</gender>
<address>
<street>197 West Park Ave.</street>
<city>New York</city>
<state>NY</state>
<zip>11375</zip>
<country>US</country>
</address>
<phone>718-235-5670</phone>
<email>[email protected]</email>
</customer>
.
customer -> firstname
lastname
gender
address ->
street
city
State
zip
Country
phone
email
Authoring XML
Documents (cont’d)
Authoring guidelines:
All elements must have an end tag.
All elements must be cleanly nested (overlapping
elements are not allowed).
All attribute values must be enclosed in quotation
marks.
Each document must have a unique first element,
the root node.
Document Type
Definitions (DTD)
An XML document may have an optional
DTD.
DTD serves as grammar for the
underlying XML document, and it is part of
XML language.
DTDs are somewhat unsatisfactory, but no
consensus exists so far beyond the basic
DTDs.
DTD has the form:
Indicator Occurrence
where <book>
<publisher>
<name> Morgan Kaufmann</name>
</publisher>
<title> $T </title>
<author> $A </author>
</book> in “www.a.b.c/bib.xml”
construct <result> $A </result>
XML-QL Query: Example 2
<store>
<name> … </name>
<phone> … </phone>
<book> <title>… </title>
<authors> … </authors>
<price> … </price>
</book>
<book>…</book>
…
</store>
Example