資訊管理研究 Internet Security Planning and Management

Download Report

Transcript 資訊管理研究 Internet Security Planning and Management

<?xml version=“1.0”?>
<簡報>
<封面>
<標題>
XML資料庫介紹
</標題>
<報告人>張景堯</報告人>
<單位>政治大學電子計算機中心</單位>
<單位>政治大學資訊管理系</單位>
<報告日期>2002年9月4日</報告日期>
</封面>
<內容>
Agenda



相關議題
XML/DB 相關產品種類定義
現有RDBMS支援XML的解決方案


MS SQL Server & XML
Oracle’s XDK
<!-- 中場休息吃點心 -->
 原生式XML資料庫



Xindice
Tamino
於電子公文系統與SCORM教材工廠應用
XML是資料庫嗎?


以極嚴謹角度思考答案為─不是
 當”XML”只是一份XML文件時;
 它頂多能視為資料的集合,跟檔案一樣。
 自身沒有任何額外的軟體(通常跟RDBMS有關連)幫助
處理或管理文件資料
從較寬鬆角度思考答案為─是的
 當”XML”除了是一份XML文件時;
 我們如果考慮到許多XML周邊所提供的能力,如:資
料存放(XML 文件)、架構輪廓(DTDs, XML Schema)、
查詢語言(XQuery, XPath, XQL, XML-QL, QUILT, etc. )
及程式介面(SAX, DOM, JDOM)
什麼是XML所欠缺的?







有效率的儲存能力
文件索引功能
文件安全性
交易與資料完整性
多使用者存取能力
資料觸發能力(Triggers)
於多重文件上的查詢能力
什麼因素讓你想用資料庫?

請自問底下問題




是否想要把過去舊有資料(Legacy Data) 呈現出來?
您是否需要個儲存網頁的地方?
資料庫是否用在某些資料交換是採用XML的應用上,
諸如電子商務應用?
您打算存的是資料還是文件?
資料vs.文件

XML文件可初略分為兩類:




以資料為中心(Data-centric)
以文件為中心(Document-centric)
兩者差別並不那麼明顯
然而,這樣的分類可幫助吾人做出採用何種資
料庫系統之正確決策。
以資料為中心的XML文件







具備文件結構非常有規律的特徵
資料很細小(Fine-grained)即資料的最小獨立
單位是PCDATA元素或屬性而已。
文件中極少或沒有混雜的資料內容。
同階層的元素順序及PCDATA出現點並不重
要。
通常是設計來給機器用的文件。
文件多僅用在資料交換上。
例如:訂單、飛機時刻表、餐廳菜單等。
範例
<Orders>
</Orders>
<SalesOrder SONumber="12345">
<Customer CustNumber="543">
<CustName>ABC Industries</CustName>
<Street>123 Main St.</Street>
<City>Chicago</City>
<State>IL</State>
<PostCode>60609</PostCode>
</Customer>
<OrderDate>981215</OrderDate>
<Line LineNumber="1">
<Part PartNumber="123">
<Description>
<p><b>Turkey wrench:</b><br />
Stainless steel, one-piece
construction, lifetime guarantee.</p>
</Description>
<Price>9.95</Price>
</Part>
<Quantity>10</Quantity>
</Line>
<Line LineNumber="2">
<Part PartNumber="456">
<Description>
<p><b>Stuffing separator:<b><br />
Aluminum, one-year guarantee.</p>
</Description>
<Price>13.27</Price>
</Part> <Quantity>5</Quantity>
</Line>
</SalesOrder>
以文件為中心的XML文件






特色是文件結構無規律
一份文件資料通常較大,即資料的最小獨立單
位可能會是混雜式元素或另一份文件。
文件中充斥著混雜的資料內容。
同階層的元素順序及PCDATA出現點很重要。
通常是設計來給人類閱讀的文件。
例如:書、電子郵件、廣告單、教材描述文件
以及幾乎概括所有XHTML文件等。
範例
<record xmlns="http://www.imsproject.org/metadata/">
<metametadata>
<metadatascheme>SCORM</metadatascheme>
</metametadata>
<general>
<title>
<langstring>XML資料庫</langstring>
</title>
<language>zh-TW</language>
<description>
<langstring>簡介能處理XML之資料庫</langstring>
</description>
<description>
<langstring>還有使用經驗分享</langstring>
</description>
</general>
…
</record>
資料、文件與資料庫



判斷您要儲存的文件是以資料為中心還是文件為中心
有助於找出適用的資料庫。
一般來說,若是以資料為主的話,則資料可存放於關
連式資料庫、物件導向資料庫或階層式資料庫,再透
過中介軟體或資料庫本身所提供XML存取能來轉換
XML文件。
若是以文件為主的話,則選用原生式XML資料庫或內
容管理系統較恰當。
XML/DB 相關產品種類定義與應用(1)



Middleware: 中介軟體用來處理來自您應用程式的呼
叫以便於XML文件及資料庫間做資料轉換工作;用於
以資料為中心的應用上。 (MS ADO, IBM XLE,
Oracle XSQL Servlet)
XML-Enabled Databases: 具備XML能力的資料庫,
擴充了原有資料庫功能可在XML文件與自身資料庫間
轉換資料。主要用於以資料為中心的應用上。(Oracle,
MS SQL, Sybase, DB2)
Native XML Databases: 原生式XML資料庫以”自
然”的方式存放XML。此名詞並未被明確定義,但概
指被設計來能維護XML結構之資料庫。以資料為中心
及文件為中心皆能應用。(Tamino, Xindice)
XML/DB 相關產品種類定義與應用(2)



XML Servers: XML伺服器能提供在各分散式應用程
式(如電子商務或B2B應用程式等)間傳遞以XML文件
為形式的資料。主要用於以資料為中心的應用上。
(HP Total-e-Business)
XML Application Servers: XML應用伺服器為Web
應用伺服器提供將XML(通常是由動態網頁產生)送至
使用者瀏覽器。以資料為中心及文件為中心皆能應用。
(Cocoon, IBM Net.Data)
Content Management Systems: 內容管理系統管理
人類可讀的文件片段,提供包含編輯、版本控制及從
現有片段建立新文件的功能。主要用於以文件為中心
的應用上。(Content@XML, GEMt)
XML/DB 相關產品種類定義與應用(3)



XML Query Engines: XML查詢引擎為單一獨
立引擎用以查詢XML文件。以資料為中心及文
件為中心皆能應用。
XML Data Binding: XML資料連結能把XML文
件連結成物件,有些產品甚至能讓您從資料庫
來存取這類物件。用於以資料為中心的應用上。
XML/DB相關產品清單,請參見:
http://www.rpbourret.com/xml/XMLDatabaseProds.ht
m
現有RDBMS支援
XML的解決方案
具備XML能力的RDBMS







透過轉換機制支援以XML為輸出入格式。
因為轉換的負擔使效能下降。
系統開發時間拉長,管理成本也增加。
各RDBMS供應商的XML轉換機制是各自建立。
檢索:搜尋能力受限於XML與SQL指令的對映限制。
擴充性差:當文件結構不同時RDBMS的適應力不如
原生式XML資料庫。
優點:可透過SQL指令查詢,不必額外訓練學習。
關連式資料庫系統與XML
 資料儲存問題


資料通常以 BLOB 型態存放(必須以額外工具才能進行功能受限的查
詢)
資料得經過 正規化 且存放在 多重資料表裡
 關連式資料庫並不懂XML或XML查詢語言



資料庫需外加一層來處理XML相關操作
造成不斷的雙向格式與結構轉換的負擔
XSQL僅允許以XML格式檢索 (而非存放) 關連式資料
 用SQL為基礎的查詢會造成系統巨大負擔

XML文件樹狀階層結構必須用複雜的資料表聯合才能查詢的了
 XML相關處理資訊是擺在資料庫核心之外

可能會浮現出潛在的參考正確性檢查(referential integrity)問題
關連式資料庫系統與XML的對映
order
Sold-to
Sold-on
19970317
Person
Smith
ORDER
PERSON
ITEM
BOOK
5.95
Pi
Author
Mapping
Code
Price
Title
Andy
Lu
Item
Book
Fname
Lname
RDBMS
•效能不彰
•查詢時會有複雜聯合
•資料更新時參考正確性限制
•擴充能力差
•資料表充斥著外鍵
Design RDBMS for Existing XML
Source: Kevin William, etc, “Professional XML Databases”
1.
Always create a primary key



2.
Basic table creation


3.
對每一結構性資料元素建立一個資料表。
若該元素只有一個母元素,則建立一個外來鍵欄位指向母元素。
Handling multiple parent elements.


4.
每個資料表皆加入一其數值會自動增值的欄位。
該欄名稱以元素名加上Key字來命名,如elementKey。
將該欄設定為主鍵值欄位。
若該元素在母元素只出現0次或1次的話,在母元素建立一外來鍵欄位指向子元
素,並設定成選擇性的或必要的。
若該元素在母元素出現0到多次或1到多次的話,加一中間資料表來表示與母元
素間的多對多關係。
Representing text-only elements.



對最多僅出現一次的純文字元素於其母元素資料表中增一欄位存放。
確保該欄位定義的大小足夠放該文字元素內容。
如該純文字元素為選擇性的,將欄位定義成可允許NULL值。
Example for Rule 1 & 2
<!ELEMENT Invoice (Customer, LineItem*)>
<!ELEMENT Customer (#PCDATA)>
<!ELEMENT LineItem (#PCDATA)>
CREATE TABLE Customer (
CustomerKey integer PRIMARY KEY)
CREATE TABLE Invoice (
InvoiceKey integer PRIMARY KEY,
CustomerKey integer
CONSTRAINT FK_Invoice_Customer FOREIGN KEY (CustomerKey)
REFERENCES Customer (CustomerKey))
CREATE TABLE LineItem (
LineItemKey integer PRIMARY KEY,
InvoiceKey integer
CONSTRAINT FK_LineItem_Invoice FOREIGN KEY (InvoiceKey)
REFERENCES Invoice (InvoiceKey))
Example for Rule 3
<!ELEMENT Invoice (Customer, LineItem*)>
<!ELEMENT Customer (Address)>
<!ELEMENT LineItem (Product)>
<!ELEMENT Product (Manufacturer)>
<!ELEMENT Manufacturer (Address)>
<!ELEMENT Address (#PCDATA)>
CREATE TABLE Customer (
CustomerKey integer PRIMARY KEY, …)
CREATE TABLE Manufacturer (
ManufacturerKey integer PRIMARY KEY, …)
CREATE TABLE Address (
CustomerKey integer NULL,
ManufacturerKey integer NULL, …)
Example for Rule 4
<!ELEMENT Customer (Name, Address, City?, State?, PostalCode)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
<!ELEMENT City (#PCDATA)>
<!ELEMENT State (#PCDATA)>
<!ELEMENT PostalCode (#PCDATA)>
CREATE TABLE Customer (
CustomerKey integer PRIMARY KEY,
Name varchar(50),
Address varchar(100),
City varchar(50) NULL,
State char(2) NULL,
PostalCode varchar(10))
Design RDBMS for Existing XML (cont.)
Representing multiple text-only elements.
5.


若只在單一母元素出現一次以上,所以建立一個資料表,含該元素的文字資
料與一外來鍵欄位指向母元素。
假如出現在多種母元素裡又不只一次以上,採用中間資料表來表示與母元素
間的關係。
Handling EMPTY elements.
6.

為每個此種元素建立一資料表,如其僅有一母元素則建立外來鍵欄位。
Representing mixed content elements.
7.




建立TableLookup資料表為資料庫中每個資料表插入一行記錄,並插入第0行
其資料表名為TextContent
建立TextContent表格,欄位為:TextContentKey(整數型態鍵值)、
ElementName(存放純文字元素之元素名)、(TextContent)存放文字內容。
建立兩個資料表:一為此元素使用直接以元素命名(如:p),另一為連結其內
各種次元素之資料表(命名如:pSubelement)
次元素資料表中需有一外來鍵指向主元素表,另一外來鍵指向TableLookup
表標明資料是放在那個資料表中、一個資料表索引鍵以找出內容是擺在哪一
行,及一序號欄以標出次元素或文字元素在主元素中的順序。
Example for Rule 5
<!ELEMENT Customer (Name+, Address, City?, State?, PostalCode)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
<!ELEMENT City (#PCDATA)>
CREATE TABLE Customer (
CustomerKey integer,
Address varchar(100),
City varchar(50) NULL,
State char(2) NULL,
PostalCode varchar(10),
PRIMARY KEY (CustomerKey))
CREATE TABLE CustomerName (
CustomerKey integer,
Name varchar(50)
CONSTRAINT FK_CustomerName_Customer FOREIGN KEY (CustomerKey)
REFERENCES Customer (CustomerKey))
Example for Rule 7
<!ELEMENT p (#PCDATA | a | br | span | bdo | object | img | map | tt | i | b |
big | small | em | strong | dfn | code | q | sub | sup | samp | kbd | var | cite |
abbr | acronym | input | select | textarea | label | button | ins | del | script |
noscript)*>
CREATE TABLE p (
pKey integer, PRIMARY KEY (pKey))
CREATE TABLE TableLookup (
TableLookupKey integer, TableName varchar(255), PRIMARY KEY (TableLookupKey))
CREATE TABLE TextContent (
TextContentKey integer, ElementName varchar(255) NULL, TextContent varchar(255))
CREATE TABLE pSubelements (
pKey integer,
CONSTRAINT FK_pSubelements_p FOREIGN KEY (pKey)
REFERENCES p (pKey),
TableLookupKey integer,
CONSTRAINT FK_pSubelements_TableLookup FOREIGN KEY (TableLookupKey)
REFERENCES TableLookup (TableLookupKey),
TableKey integer, Sequence integer)
Design RDBMS for Existing XML (cont.)
8.
Handling the “ANY” content elements.

9.
CDATA attributes


10.


屬性是#REQIURED – 表每筆record中必有此資料。
屬性是#IMPLIED – 表此欄位允許NULL值。
屬性是#FIXED – 原則上不必進資料庫,有必要才放進去。
ENUMERATED attributes



12.
在含此屬性之元素的資料表中加入一個此屬性的欄位。
設定資料型態為varchar並依經驗設定最大長度。
REQUIRED/IMPLIED/FIXED attributes

11.
作法與處理mixed content element方式一樣。
為此屬性在該元素資料表中建立一個欄位,但只存放代碼。
建立一個對照表(Lookup Table)存放所有可能的數值列。
每次插入資料時都到對照表轉譯成代碼後再存入該元素的資料表中。
Handling ID attributes


若該ID屬性資料帶有意義者,將其當作CDATA存進資料庫中。
若該ID屬性資料表示為主鍵值,可以拿它來insert或update資料庫資料。
Design RDBMS for Existing XML (cont.)
13.
Handling IDREF attributes


14.
Handling IDREFS attributes



15.
對每個NMTOKENS型態屬性建立一資料表,含:一自動增值之主鍵、一指向元素
資料表的外來鍵與TOKEN字串欄位。
ENTITY and ENTITES attributes

18.
對每個NMTOKEN型態屬性建立一欄位。
NMTOKENS attributes

17.
若只指向一種特定元素的話,建立一個join table,內容為兩個互相有關係的外來鍵
值。
若指向不只一種元素的話,則透過建立TableLookup表格方式,指向相應的鍵值。
在關係表中與lookup table間要建立外來鍵設定。
NMTOKEN attributes

16.
若只指向一種特定元素的話,則當作外來鍵指向以該ID屬性為主鍵值的元素。
若指向不只一種元素的話,則透過建立TableLookup表格方式,指向相應的鍵值。
處理方式同NMTOKEN與NMTOKENS
Check for name collisions

檢查所有表格,如有名稱衝突,就改名。
Example for Rule 13
<!ELEMENT Order (Customer, Invoice)>
<!ELEMENT Customer EMPTY>
<!ATTLIST Customer
CustomerID ID #REQUIRED>
<!ELEMENT Invoice EMPTY>
<!ATTLIST Invoice
InvoiceID ID #REQUIRED
CustomerIDREF IDREF #REQUIRED>
CREATE TABLE Customer (
CustomerKey integer,
PRIMARY KEY (CustomerKey))
CREATE TABLE Invoice (
InvoiceKey integer,
CustomerKey integer
CONSTRAINT FK_Invoice_Customer FOREIGN KEY (CustomerKey)
REFERENCES Customer (CustomerKey))
不利於RDBMS的基本論點(1)
 關連式資料庫管理系統是設計用來對關連式資料幹活的

假如資料無法被簡單地正規化則採用關連式解決方案是不妥的。
 關連式資料庫無法處理複雜的XML階層/巢狀結構






形成太多資料表
形成太多外部參考
形成太多外鍵
資料表聯合太複雜
查詢很麻煩
無物件鎖定功能
不利於RDBMS的基本論點(2)
 關連式資料庫提供許多存放選擇,這是因為沒有一種
是好的方案

BLOBs 型態資料無法輕易地查詢

BLOBs 型態資料無法輕易地更新

把XML資料存放在多重資料表中會造成效能的負
荷,所以必須儘量少採用此方法。
MS SQL Server
&
XML
從SQL Server存取XML
(SQL Server 2000 with XML extensions)
SQL Server 2000: SQLXML


Microsoft’s Mapping technology (and more…)
Shipped with SQL Server 2000






Two subsequent releases have shipped to the Web
Provides a rich XML view of relational data
Semi-structured, hierarchical view of flat relational
data
Two-way view: query and update
Multiple access mechanisms (HTTP, ADO,
ADO.NET, SOAP)
Middle-tier and Server side support
Query/Update Technologies

FOR XML (raw, auto, nested, explicit)


XML Views


Shred large XML files into existing tables
Updategrams


Work with your relational database as if it was XML file
(through annotated schema)
Bulkload


SQL language extension to retrieve XML instead of
rowsets
Update through XML View
XPath query support
Architecture
XML
XML
XMLBulkload
BCP/SQL
Updategrams
SQL update/
insert/ delete
SQL
Server
Annotated XSD
Mapping Schemas
FOR XML
Query
Query Processor
XML
XPath
SQL
Queries
FOR XML
Queries FOR XML
Queries
Rowsets
SQL
Queries
FOR XML
Mapping Technologies




Optimized for data-centric documents
“Shredding” of XML documents into and out of nonXML logical model, e.g. Relational
Provides a denomalized logical view on top of highly
structured, normalized data
User-defined mapping




Not all data may be mapped to the destination
Physical structure may be lost
Schema-less content might be discarded
In some cases, a default (system-defined) mapping
may suffice
XML Views



Map between relational data and XML
Declarative
Noninvasive



No changes to legacy data sources
No control over DB Server required
XML View is an XML Schema

XSD and XDR supported
Default Mapping Example
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema“
xmlns:msdata="urn:schemas-microsoft-com:mapping-schema“>
<xsd:element name=“Customers”>
<xsd:complexType>
<xsd:attribute name=“CustID”/>
</xsd:complexType>
</xsd:element >
</xsd:schema>
XML View
<Customers CustID=“A”/>
<Customers/>
<Customers CustID=“B”/>
Relational Data:
Customers Table
CustID
-----A
NULL
B
Explicit Mapping Example
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema“
xmlns:msdata="urn:schemas-microsoft-com:mapping-schema“>
<xsd:element name=“Customers” msdata:relation=“tblCustomers">
<xsd:complexType>
<xsd:attribute name=“ID” msdata:field=“pkCustID"/>
</xsd:complexType>
</xsd:element >
</xsd:schema>
Relational Data:
tblCustomers Table
<Customers ID=“A”/>
<Customers/>
<Customers ID=“B”/>
pkCustID
-----A
NULL
B
XML Results from SQL Server
Query:
"SELECT name,address FROM EmpTable FOR XML AUTO"
XML result:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<EmpTable name="Tom" address="123 Main St"/>
<EmpTable name="Maria" address="456 Broadway"/>
</ROOT>
•AUTO mode uses table name for row element
•RAW mode uses 'row' for the row element
ADO.NET and XML
Controls,
Designers,
Code-gen, etc
XSL/T, X-Path,
etc
DataSet
Mapping
DataAdapter
DataReader
Command
Connection
.NET Data Provider
XmlDataDocument
XmlReader
ADO.NET and XML

The DataSet




Loads/saves XML data into/out of DataSet
Schema can be loaded/saved as XSD
Schema can be inferred from XML Data
The DataSet can be associated with an
XmlDataDocument

Exposes a relational view over structured XML




According to the DataSet schema
Allows strong typing, control binding, relational access of
XML data
Allows XML tools (schema validation, XSL/T, XPath
queries) against relational data
Preserves full fidelity of XML Document
Loading XML
// Load DataSet with XML
DataSet ds = new DataSet();
ds.ReadXml("inventory.xml");
// Add a record to the Inventory table
DataTable inventory = ds.Tables["Inventory"];
DataRow row = inventory.NewRow();
row["TitleID"]=1;
row["Quantity"]=25;
inventory.Rows.Add(row);
// Write out XML
ds.WriteXml("updatedinventory.xml");
Oracle’s XDK
XML Development Kit
Support for XML in Oracle Products
XML Developer Kit




XML Parser
XSLT Processor
XSQL Pages
XML SQL Utility
Oracle 9i SYS.xmltype Datatype
Oracle Text
JDeveloper
PLSXML
XML Developer Kit (XDK)
A single Oracle module that XML-enables
your Oracle database
Features based on XML standards:



XML parser
DOM and SAX support
XSLT processor
Oracle-specific features:


XSQL pages
XML SQL utility
XDK Availability and Compatibility



Installs automatically with Oracle 9i and Oracle 8i
Release 3 (8.1.7) databases
Available for Oracle 8i Release 1 and 2 from the
Oracle Technology Network at technet.oracle.com
Not available for Oracle7 or Oracle8
Oracle’s XDK is evolving rapidly. Check OTN
periodically to see if a newer version of the XDK is
available for download.
XDK Fun Facts



Java applications can run inside or outside
the database.
You must install Oracle’s JVM in the
database in order to run PL/SQL applications
that use Oracle’s XDK.
Some XDK features (such as SAX support
and XSQL pages) are only available in the
XDK for Java.
Oracle Java/XML Tools
XML Parsers
XML Class Generators
XML SQL Utility for Java
XSQL Servlet
XML Schema Processor
XML Class Generator
DTD
parser
Class Generator
Java classes
(one per element)
User written
Java Application
Valid document
XML SQL Utility
A facility for loading XML documents into the database and
retrieving data from the database into XML documents,
without storing the XML text in one large CLOB column




Invoke an XSLT to transform data from any format into a
<ROWSET><ROW> style XML document.
Convert the <ROWSET><ROW> document into a SQL
INSERT statement and load the data into a table.
Capabilities exist for updating and deleting data as well.
Extract data from the database into a document of any format
by reversing the process.
Oracle SQL Utility for Java
Select EMPNO,ENAME from EMP
Where EMPNO = 7654
<?xml ?>
<ROWSET>
<ROW id=“1”>
<EMPNO>7654</EMPNO>
<ENAME>Martin</ENAME>
</ROW>
</ROWSET>
SQL Util
For Java
Writing to the DB
If data is in standard XML form (see previous page)
OracleXMLSave s = new OracleXMLSave ( conn, “EMP”);
URL url = s.createURL ( xmlFile );
Rowcount= s.insertXML( url );
conn.close();
.XSQL file
File.xsql
XSQL
Servlet
<?xml version=“1.0” ?>
<?xml-stylesheet href=“a.xsl ? media="IE5">
<query
Default value
connection=“demo”
sort=“ENAME” >
SELECT * FROM EMP ORDER BY {@sort }
</query>
XSQL Servlet Processing
•Client hits XSQL file with
“http://…/file.xsql?sort=EMPNO”
•SQLServlet parses XSQL, creates DOM tree
•SQL Page Processor passes XML parms and SQL stmts to
SQL Utility
•SQL Page Processor passes any XSL PI’s to XSLT Processor
•SQL util sends SQL stmt to db, returns XML to replace the
<query> tags in the .xsql DOM
•XSLT processor runs transform against the stylesheet, returns
results to browser
XSQL Servlet
2
client
1
XML Parser
File.xsql
“query XML”
3
4
client
9
XSQL
PageProcessor
XSQL
Servlet
XSQL Util
5
8
XSL files
XML
Results
7
6
中場休息二十分鐘
原生式XML資料庫
Native XML DB
何謂原生式XML資料庫




直接以XML文件而非用文件中的資料來定義資料模型,
並以該模型來儲存或檢索文件。
該模型(如XPath資料模型)應至少包含元素、屬性、
PCDATA及文件順序的定義。
以XML文件為基本儲存單位,就像關連式資料庫是以
資料表中的列(Row)為基本儲存單位一般。
不需要任何特定的底層實體儲存模型,也就是它可以
建構於關連式、階層式或物件導向式資料庫上,也能
運作在專屬儲存結構如壓縮檔等。
原生式XML資料庫管理系統特色






直接支援以XML為輸出入格式。
沒有額外的轉換負擔效能較佳。
開發者及系統管理者都不需要在XML與SQL間
變換。
原生XML對標準的支援較能一致。
檢索:支援原生XML搜尋能力,增進搜尋效能。
可擴充性:能悠哉的處理XML文件結構的改變。
為何用原生式XML資料庫






直截了當地存放XML。
具備XML導向的查詢機制。
能處理半結構化資料。
能輕易建構起鬆散耦合應用程式。
對文件結構改變有極大彈性與處理能力。
並不用來取代RDBMS。
原生式XML資料庫和其他資料庫比較



為何不用關連式資料庫
為何不用物件導向資料庫
為何不直接用搜尋引擎就好
原生式XML資料庫
XML database
order
order
Sold-to
Sold-on
19970317
Sold-to
Item
Sold-on
1997031
7
Person
Person
Fname
Pi
Author
Lu
5.95
Title
Andy
Lname
Price
Book
Smith
Price
5.95
Book
Fname
Andy
Lname
Lu
Item
Title
Pi
Author
Smith
• Database schema automatically
built from DTD
• No Mapping required
• Native Storage
• High Performance
Native XML Storage
XML
SQL
XML
XML over SQL is bad
Native XML is right
This is slow, difficult and
proprietary
This ensures performance,
data integrity and extensibility
How Do You Query
W3C XPath
•
•
•
Most common language currently used
XPath 2.0 – 30 April, 2002
W3C XQuery
•
•
XQuery 1.0 – 30 April, 2002
Proprietary Languages
•
•
Over time these will go away
Querying with XPath
Simple yet powerful path based XML query
language
•
•
/root/node[criteria = 'value']
Many products extend XPath to allow
queries across collections of documents
Limited in many ways
•
•
•
•
•
No grouping
No sorting
Limited data typing
Querying with XQuery






Builds on top of XPath and XML Schema data types
Enables full data-typing
Allows joins between XML documents
Allows sorting and grouping
Language is SQL like but works on trees rather then
tables
A complete query language for XML documents


Access collections of XML documents like SQL with
relational tables
Flexible, composable, optimizable
How do you Update Data
W3C DOM / SAX / JDOM
XML:DB XUpdate
•
•
•
•
Usable today
Useful beyond just XML databases
W3C XQuery update extensions
•
•
•
•
Expected at some point in the future
Not be part of XQuery 1.0
Experimental syntax does exist
Schemas
•
•
•
•
Most native XML databases are schema
independent
DTDs - Just say no
Proprietary or extended DTDs
W3C XML Schema will likely be supported
more widely in the future.
The Bad
•
•
•
•
•
•
•
Products are immature
Many standards are still in development
Techniques are unfamiliar to people
Not good at transaction processing
Tool support is minimal
Some expected database practices are still
unsupported
Interoperability between products is
minimal
The Good
•
•
•
•
•
•
•
Good way to store XML
Can store document or data style XML
Tremendous flexibility
Applications can be loosely coupled
Data modeling is simple and flexible
Complement RDBMS with XML mapping
solutions
Performance can be very good
Xindice
開放原始碼的原生式XML資料庫
What is Xindice?









Pronounced "Zeen-dee-chay”
The Apache Native XML Database
Faster for XML than other databases
No mapping to relational required
Stores documents in tokenized form
Provides quick fragment retrieval
Uses XML-specific indexing schemes
Supports optimized XML querying
Part of Sun’s Web Services Developer Kit
Origins of the Xindice Project








Xindice was previously named dbXML Core
First open source native XML database
Project started in June of 1999
Founded by Tom Bradford
Managed by Kimbro Staken
Most widely deployed XML database
Invited to Apache Foundation in 2001
Renamed Xindice for Apache Project
Document Collection System











Top level object is a Database
Database is a special Collection
Database maintains symbol tables
SystemCollection stores DB metadata
Basic unit of data is a Document
Sets of Documents are Collections
Collections may contain Collections
Think of it as a file system for XML
Collections may be indexed
Collections may maintain XMLObjects
XMLObjects are like Stored Procs
Querying with XPath







Specified by the WWW Consortium
Querying syntax similar to UNIX paths
Supports more advanced expressions
Supports flexible node filtering
Can select single or multiple nodes
Can utilize and return function results
Xindice extends XPath to collections
XPath Examples
Select books with an isbn attribute equal to ‘1884777368’
/book[@isbn="1884777368"]
Select books with a title value starting with ‘Learning’
/book[title[starts-with(.,’Learning’)]]
Select the title of all books
/book/title
Select all books whose price is less than ‘10.50’ in American dollars
/book[price[@currency=’US’ and .<10.50]]
Querying with XUpdate






Specified by the XML:DB Initiative
An XML syntax for batch modifications against sets
of XML documents
Several operations can be performed against a
collection at one time
Leverages the filtering capabilities of the XPath
resolver using selectors
Selectors operate against collections
Has several limitations, but is here now
The Future of Apache Xindice








Support for the W3C’s XQuery language
Support for W3C XML Schemas
Full-text and Schema-aware Indexing
Integration with the Labrador web service framework
for SOAP, XML-RPC, and WSDL
Tighter coupling with other Apache XML projects,
including Xalan and Cocoon
WebDAV content management facilities
Full transactional capabilities
Full security implementation
Tamino XML
Database
提供XML文件儲存、管理、發行及交換的服務
Tamino XML 資料伺服器的位階
資料庫伺服器
應用伺服器
Oracle, DB2, MS SQL etc.
WebSphere, WebLogic etc.
訊息整合伺服器
EntireX , WebSphere MQ etc.
Architecture
Tamino Manager
XML Parser
&
Query
Interpreter
Object
Processor
& Object
Composer
X-Tension
World
Wide
Web
HTTP
Consumer
(e.g. Browser)
Electronic
Business
Client
XML, Queries
New
&
Existing
Applications
(e.g. Browser)
XML, HTML,
WML, ...
Native XML
Data Store
X-Node
SDK
Data
Map
Adabas
Office
SQL
Infomix /
RDBMS
Features & Benefits
 The world’s fastest XML Database / Server

Native Storage of XML-Objects w/o conversion into other formats
 Integration of data in existing, external data sources

Access to and modification of data from diverse systems
(relational DBs, object DBs, Office-Systems...)
 Database Queries with ‘XQuery’

XPath-based - regarding document structure and content
 Simple administration

Browser-based control via any PC having Internet access
 Simple connection to Internet via standard WebServer
Features & Benefits
 Security

Group / User authorization rights down to XML Element level
 Read-Only databases supported
 Dynamic Style-Sheet processing supported

e.g. HTML formatted output of XML documents
The Communication Interface
Application
Web Browser
http://www.ebiz1.com/tamino/xml
HTTP
Web Server
X-Port
Port 3204
Port 3207
Apache,
MS IIS, IBM, Netscape
Port 3210
Tamino Server
Tamino Server
Tamino Server
"xml"
"mydata"
"test1"
Native XML Server
XML Documents
XQL
Query
X-Machine
XML Data Store
XML
Output
Java/JScript/COM API
Tamino DOM APIs
Application
Application//
Web
WebBrowser
Browser
TaminoClient
Object
TaminoResult
Object
DOM Tree
Tamino Server
6 - 12
Tamino Java API
The Most Common Operations





Establish a connection to the existing
Tamino database SCORM
Obtain an access method to handle XML
data using the Document Object Model
(DOM)
Insert an XML document into the database
Query the database to retrieve the
document inserted previously
Close a database connection
XML資料庫操作展示

展示環境




Tamino版本3.1.1.4
OS: MS Windows 2000 Professional
CPU/RAM: Pentium III 733MHz/128MB
DB Server URI


http://140.119.210.104/tamino/SCORM
說明文件資源

http://140.119.210.104/tamino-v3.1.1.4/welcome/index.html
展示參數


Default Collection: ino:etc
電子公文






http://140.119.210.104/tamino/GD/
Root - 函
http://140.119.210.104/tamino/GD/ino:etc?_XQL=函
&_encoding=big5
http://140.119.210.104/tamino/GD/ino:etc?_XQL=函[主旨/
文字~='教育部']/主旨&_encoding=big5
http://140.119.210.104/tamino/GD/ino:etc?_delete=函[主旨/
文字~='教育部']&_encoding=big5
SCORM教材工廠


http://140.119.210.104/tamino/SCORM/
Root - record
參考資料與聲明









Adam Malik, “XML and databases:Points of integration ,”, Lever
Existing Computing Assets on XML Fulcrum Conference, 2000/11
Dave Reed, “XML and Databases,” XML 2001, Microsoft Corp.
Eva Tai, “Accelerate your evolution to e-business,” Software AG
Taiwan.
Kimbro Staken, “Native XML Databases : Why Bother?,”
http://www.dbxml.org/
Roger Schrag, “XML and Oracle: An Overview,” Database Specialists,
Inc.
Ronald Bourret, “XML and Database,”
http://www.rpbourret.com/xml/XMLAndDatabases.htm
Ronald Bourret, “XML Database Products,”
http://www.rpbourret.com/xml/XMLDatabaseProds.htm
Tom Bradford, “Introducing the Apache Native XML Database,”
http://www.tbradford.org/
本投影檔為教學研究用途參考以上資料製作,未經上述作者許可授權不
得用以營利。
</內容>
<結束語>
謝謝大家聆聽,請不吝賜教
</結束語>
</簡報>