数据库查询事务
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
17
Example: (a)
<?xml version = “1.0” standalone = “no” ?> <!DOCTYPE BARS [ <!ELEMENT BARS (BAR*)> The DTD <!ELEMENT BAR (NAME, BEER+)> <!ELEMENT NAME (#PCDATA)> <!ELEMENT BEER (NAME, PRICE)> The document <!ELEMENT PRICE (#PCDATA)> ]> <BARS> <BAR><NAME>Joe’s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> … </BARS>
13
Example: DTD
<!DOCTYPE BARS [ <!ELEMENT BARS (BAR*)> <!ELEMENT BAR (NAME, BEER+)> A BAR has one NAME and one <!ELEMENT NAME (#PCDATA)> or more BEER <!ELEMENT BEER (NAME, PRICE)> subobjects. <!ELEMENT PRICE (#PCDATA)> A BEER has a ]>
<!ATTLIST element-name, attribute-name, type>
DTD or XML scheBiblioteka Baidua
XML Document
Validating XML Parser
Parsed XML
“Not valid”
12
DTD Structure
<!DOCTYPE <root tag> [ <!ELEMENT <name>(<components>)> . . . more elements . . . ]>
Get the DTD from the file bar.dtd
19
Attributes
Opening tags in XML can have attributes. In a DTD, <!ATTLIST E . . . > declares attributes for element E, along with its datatype. The declaration of the form:
Relational database Valid XML Well-formed XML
from strict Structure to loose Structure
7
Well-Formed
XML
keep basic structural requirements
• Single root element • Matched tags, proper nesting • Unique attributes within elements
complex implied
Simple, high level language none
6
Well-Formed and Valid XML
Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD, or XML schema .
11
Valid XML
Each XML needs a standard to define what are valid elements, using XML type specification languages to specify the syntax DTD (Document Type Descriptors) XML Schema Plus textual descriptions of the semantics
Notice a new kind of data.
award Gold
name
Joe’s
3
XML
XML = Extensible Markup Language. HTML uses tags for formatting (e.g., “italic”), XML uses tags for semantics (e.g., “this is an address”). Key idea: create tag sets for a domain, and translate all data into properly tagged XML documents.
16
Use of DTD’s
1. Set standalone = “no”. 2. Either:
a) Include the DTD as a preamble of the XML document, or b) Follow DOCTYPE and the <root tag> by SYSTEM and a path to the file where the DTD can be found.
2
Example: Data Graph
root bar beer manf name servedAt Bud A.B. beer manf name M’lob addr Maple The bar object for Joe’s Bar The beer object for Bud prize year 1995
10
Example: Well-Formed XML
A NAME <?xml version = “1.0” standalone = “yes” ?> subelement <BARS> <BAR><NAME>Joe’s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> Root tag <PRICE>3.00</PRICE></BEER> A BEER subelement </BAR> <BAR> … Tags </BARS> • Single root element surrounding • Matched tags, proper nesting a BEER element • Unique attributes within elements
* = zero or more. + = one or more. ? = zero or one.
Symbol | can connect alternative sequences of tags.
15
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: <!ELEMENT NAME ( (TITLE?, FIRST, LAST) | IPADDR )>
NAME and PRICE are text. NAME and a PRICE.
A BARS object has zero or more BAR’s nested within.
14
Element Descriptions
Subtags must appear in order shown. A tag may be followed by a symbol to indicate its multiplicity.
Chapter 11 The semi-structured data model
Structured data XML (http://www.w3.org/XML/) Document Type Definitions XML Schema
1
Graphs of Semistructured Data
18
Example: (b)
Assume the BARS DTD is in file bar.dtd.
<?xml version = “1.0” standalone = “no” ?> <!DOCTYPE BARS SYSTEM ”bar.dtd”> <BARS> <BAR><NAME>Joe’s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> … </BARS>
XML Document
XML Parser
Parsed XML
“Not well-formed”
8
Well-Formed XML (cont.)
Start the document with a declaration, surrounded by <?xml … ?> . Normal declaration is: <?xml version = ”1.0” standalone = ”yes” ?>
Nodes = objects. Labels on arcs (like attribute names). Atomic values at leaf nodes (nodes with no arcs out). Flexibility: no restriction on:
Labels out of a node. Number of successors with a given label.
4
XML: Motivation
Data interchange is critical in today’s networked world Examples: Banking: funds transfer Order processing (especially inter-company orders) Scientific data Paper flow of information between organizations is being replaced by electronic flow of information Each application area has its own set of standards for representing information XML has become the basis for all new generation data interchange formats
“standalone” = “no DTD provided.”
Balance of document is a root tag surrounding nested tags.
9
Well-Formed XML (cont.)
Tags are normally matched pairs, as <FOO> … </FOO>. Unmatched tags also allowed, as <FOO/> Tags may be nested arbitrarily. XML tags are case-sensitive.
5
Comparison with Relational Data
Relational Structure Schema Queries Ordering
Table fixed
XML
Tree, graph Non rigid format Flexible Tags self describing Allows nested structures