Database - Discussions
XML: Extensible Markup Language
Dr. Buleje
Introduction
Databases function as data sources for Web
applications
HTML
Used in static Web pages
XML, JSON
Self-describing documents
Dynamic Web pages
Slide 13- 2
Structured, Semistructured, and
Unstructured Data
Structured data
Semi-structured data
Un-structured data
Slide 13- 3
Directed Graph Model for
Semistructured Data
Slide 13-4
Figure: Representing semistructured data as a graph
Structured, Semistructured, and
Unstructured Data (cont’d.)
HTML uses predefined tags
Document header
Body
Table tags
Attributes
Large number of predefined tags
XHTML
Slide 13- 5
XML Hierarchical (Tree) Data Model
Basic object: XML document
Element
Attribute
Document types
Data-centric
Document-centric
Hybrid
Slide 13- 6
XML Documents, and XML Schema
Conditions for well-formed XML documents
Notation for specifying elements
elementname* indicates optional multivalued (repeating) element
elementname+ indicates required multivalued (repeating) element
elementname? indicates optional single-valued (non-repeating) element
elementname indicates required single-valued (non-repeating) element
Slide 13- 7
XML Documents, and XML Schema
(cont’d.)
Notation for specifying elements (cont’d.)
Type specified by parentheses following the
element name
!ATTLIST used to specify attributes within the element
Parentheses can be nested when specifying elements
Bar symbol (e1|e2) indicates either e1 or e2 can appear in the document
Slide 13- 8
XML Schema
XML schema language
XML namespace
Elements and types
Slide 13- 9
XML Schema (cont’d.)
Keys
Complex elements
xsd:complexType
Composite attributes
Slide 13- 10
Storing and Extracting XML
Documents from Databases
File system / DBMS: store documents as text
DBMS to store document contents as data
elements
Design specialized system to store XML data
Create or publish custom XML documents from
preexisting relational databases
Slide 13- 11
XML Languages
Query language standards
XPath
XQuery
Specifying XPath expressions in XML
Example
For COMPANY.XML document stored at location
www.company.com/info.XML
doc(www.company.com/infor.XML)/company
returns company root node and all descendant
nodes
Slide 13- 12
XQuery: Specifying Queries in XML
FLWOR expression
Variables preceded with $
FOR assigns variable to a range
WHERE specifies additional conditions
ORDER BY specifies order of result elements
RETURN specifies elements for retrieval
Slide 13- 13
XQuery: Specifying Queries in XML
Example
Slide 13- 14
XML/SQL: SQL Functions for
Creating XML Data
XMLELEMENT
XMLFOREST
XMLAGG
XMLROOT
Slide 13- 15
XML/SQL: SQL Functions for
Creating XML Data (cont’d.)
XMLATTRIBUTES
Creates attributes for the elements of the XML
result
Example: create XML element containing the
EMPLOYEE lastname for the employee with SSN
123456789
Result:
Slide 13- 16
Summary
Structured, semistructured, and unstructured data
Hierarchical data model of XML standard
Languages for specifying structure
Approaches for storing XML documents
XPath and XQuery languages
SQL/XML allows formatting query results as XML
data
Slide 13- 17