Anda di halaman 1dari 14

MENGGUNAKAN XML

SEBAGAI BASIS DATA

PSBD

DAFTAR ISI
Part 1: Dasar pembuatan dokumen XML
Part 2: Melakukan query pada dokumen XML

LATAR BELAKANG
An Extensible Markup Language (XML) document describes the
structure of data
XML and HTML have a similar syntax both derived from SGML
XML has no mechanism to specify the format for presenting data to
the user
An XML document resides in its own file with an .xml extension

ATURAN DASAR
XML is case sensitive
All start tags must have end tags
Elements must be properly nested
XML declaration is the first statement
Every document must contain a root element
Attribute values must have quotation marks
Certain characters are reserved for parsing

CONTOH PENGGUNAAN
Example 3: Elements with Children
To specify that an element must have a single child element, include the element name within the parenthesis.
<!ELEMENT House (Address)> <!A house has a single address-->
<House> <!Valid usage within XML file-->
<Address>1345 Preston Ave Charlottesville Va 22903</Address>
</House>
An element can have multiple children. A DTD describes multiple children using a sequence, or a list of elements separated by commas. The XML
file must contain one of each element in the specified order.
<!--DTD declaration of an element-->
<!ELEMENT address (person,street,city, zip)>
<!ELEMENT person (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city
(#PCDATA)>
<!ELEMENT zip
(#PCDATA)>
<!Valid usage within XML file-->
<address>
<person>John Doe</person>
<street>1234 Preston Ave.</street>
<city>Charlottesville, Va</city>
<zip>22903</zip>
</address>

XQL
XQL - XML Query Language
The name was an ad hoc selection, but seems like it has and will
survive for quite some time

XQL DESIGN (1)


Compact, easy to type and read
Simple for common cases
Embeddable in programs, scripts, URLs
Unique identification of each node
Declarative NOT procedural
Evaluation at any level in the document
Result in document order; no repeat node

XQL DESIGN (2)


Superset of XSL
Closure is guaranteed ONLY if the implementation returns wellformed XML documents

XQL: SYNTAX (1)


Mimics the URI navigation syntax
Notation
/
./
//
.//
@
*

:
:
:
:
:
:

Root context
Current context
Recursive descent from root
Recursive descent from current node
Attribute
Any element

SAMPLE DOCUMENT
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore specialty='novel'>
<book style='autobiography'>
<title>Seven Years in Trenton</title>
<author>
<first-name>Joe</first-name>
<last-name>Bob</last-name>
<award>Trenton Literary Review Honorable Mention</award>
</author>
<price>12</price>
</book>
<my:book style='leather' price='29.50' xmlns:my='http://www.placeholder-name-here.com/schema/'>
<my:title>Who's Who in Trenton</my:title>
<my:author>Robert Bob</my:author>
</my:book>
</bookstore>

XQL: EXAMPLES (1)


./author author
/bookstore
//author .//author
book[bookstore/@specialty = @style]
author/first-name
author/*
bookstore//title bookstore/*/title
*[@specialty]

XQL: EXAMPLES (2)


book[@style]
book/@style
book[excerpt]/author[degree]
book[excerpt][title] book[excerpt $and$ title]
author[name = ] author[name $eq$ ]
author[. = Bob] author[text() = Bob]
author[first-name!text() = Bob]
degree[index() $lt$ 3] degree[index() < 3]

XQL: EXAMPLES (3)


<x>
<y/>
<y/>
</x>
<x>
<y/>
<y/>
</x>

x/y[index() = 0] x/y[0]
(x/y)[0]
x[0]/y[0]
book[end()]
author[first-name][2]
price[@intl!value() = canada]
my:*
*:book
book/@my:style

XQL: EXAMPLES (4)


author[publications!count() > 10]
books[pub_date < date(1995-01-01)]
books[pub_date < date(@first)]
bookstore/(book | magazine)
//comment()[1]
ancestor(book/author)
author[0, 2 $to$ 4, -1]

Anda mungkin juga menyukai