Download presentation
Presentation is loading. Please wait.
1
Managing XML and Semistructured Data Lecture 17: Publishing XML Data From Relations Prof. Dan Suciu Spring 2001
2
In this lecture XML Publishing Example XML Publishing Languages Virtual XML Publishing Materialized XML Publishing (next time) Resources SilkRoute: Trading between relations and XML by Fernandez, Suciu, Tan R, in WWW9, 2000SilkRoute: Trading between relations and XML Efficient Evaluation of XML Middle-ware Queries in SIGMOD'2001Efficient Evaluation of XML Middle-ware Queries
3
XML Publishing Today: Legacy data –fragmented into many flat relations –3rd normal form –proprietary XML data –nested –un-normalized –public (450 schemas at www.biztalk.org)
4
XML Publishing: an Example Eu-Stores US-Stores Products Eu-SalesUS-Sales namecountrynameurl date tax name priceUSD euSidusSid pid Legacy data in E/R:
5
XML Publishing: an Example XML view France Nicolas Blanc de Blanc 10/10/2000 12/10/2000 … … … …. … In summary: group by country store product
6
allsales country namestore nameproduct namesold datetax url PCDATA * * * * ? ? Output “schema”:
7
XML Publishing Need a language for specifying the Relational XML mapping SilkRoute: –a SQL/XML-QL blend IBM (formerly Experanto project) –extension of SQL SQL Server: –“FOR XML” – and extension of SQL –XDR’s
8
{ FROM EuStores $S, EuSales $L, Products $P WHERE $S.euSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT $S.country $S.name $P.name $P.priceUSD } /* union….. */ { FROM EuStores $S, EuSales $L, Products $P WHERE $S.euSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT $S.country $S.name $P.name $P.priceUSD } /* union….. */ XML Publishing: SilkRoute In SilkRoute [Fernandez, Suciu, Tan ’00]
9
XML Publishing : SilkRoute …. /* union */ { FROM USStores $S, EuSales $L, Products $P WHERE $S.usSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT USA $S.name $S.url $P.name $P.priceUSD $L.tax } …. /* union */ { FROM USStores $S, EuSales $L, Products $P WHERE $S.usSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT USA $S.name $S.url $P.name $P.priceUSD $L.tax }
10
Non-recursive datalog (SELECT DISTINCT … ) allsales() country(c) name(c)store(c,x) name(n)product(c,x,y) name(n)sold(c,x,y,d) date(c,x,y,d) Tax(c,x,y,d,t) url(c,x,u) c n n d t u Internal Representation country(c) :-EuStores(x,_,c), EuSales(x,y,_), Products(y,_,_) country(“USA”) :- store(c,x) :- EuStores(x,_,c), EuSales(x,y,_), Products(y,_,_) store(c,x) :- USStores(x,_,_), USSales(x,y,_), Products(y,_,_), c=“USA” url(c,x,u):-USStores(x,_,u), USSales(x,y,_),Products(y,_,_) allsales():- * * * * ? View Tree:
11
XML Publishing : IBM XPERANTO: Publishing Object-Relational Data as XML, Carey, Florescu, Ives, Lu, Shanmugasundaram, Shekita, Subramanian, WebDB’2000 Efficiently Publishing Relational Data as XML Documents, Shanmugasundaram, Shekita, Barr, Carey, Lindsay, Pirahesh, Reinwald, VLDB’2000
12
XML Publishing : IBM (Select S.name, STORE(S.euSid, S.name, (Select XMLAGG(PRODUCT(P.pid, P.name, P.priceUSD)) From EuSales L, Products P Where S.euSid = L.euSid AND L.pid = P.pid)) From EuStores S) Union All..... (Select S.name, STORE(S.euSid, S.name, (Select XMLAGG(PRODUCT(P.pid, P.name, P.priceUSD)) From EuSales L, Products P Where S.euSid = L.euSid AND L.pid = P.pid)) From EuStores S) Union All..... Define XML Constructor STORE(storeID: integer, name: varchar(20), prodList: xml) AS { $name $prodList } Define XML Constructor STORE(storeID: integer, name: varchar(20), prodList: xml) AS { $name $prodList } Define XML Constructor PRODUCT(...) AS {... } Define XML Constructor PRODUCT(...) AS {... } SQL + User defined functions
13
XML Publishing : SQL Server Three modes RAW mode Auto Mode Explicit Mode
14
XML Publishing : SQL Server, RAW Mode Select S.euSid, L.euSid, P.name, P.price From Stores S, EuSales L, Products P Where S.euSid != L.euSid AND L.pid = P.pid For XML Raw Select S.euSid, L.euSid, P.name, P.price From Stores S, EuSales L, Products P Where S.euSid != L.euSid AND L.pid = P.pid For XML Raw.... flat XML default tag and attribute names
15
XML Publishing : SQL Server Auto Mode Select S.euSid, P.name, P.price From Stores S, EuSales L, Products P Where S.euSid = L.euSid AND L.pid = P.pid For XML Auto Select S.euSid, P.name, P.price From Stores S, EuSales L, Products P Where S.euSid = L.euSid AND L.pid = P.pid For XML Auto.............. nested XML default tag and attribute names
16
XML Publishing : SQL Server Explicit Mode Nested XML User defined tags and attributes Idea: write SQL queries with complex column names Ad-hoc, order dependent semantics
17
XML Publishing : SQL Server Explicit Mode (Select 1 as Tag, null as Parent, S.euSid as [Store!1!id], S.name as [Store!1!name!element], null as [Product!2!name!element], null as [Product!2!price!element] From Stores S) Union All (Select 2 as Tag, 1 as Parent, S.euSid as [Store!1!id], null as [Store!1!name!element], P.name as [Product!2!name!element], P.price as [Product!2!name!element] From Stores S, EuSales L, Products P Where S.euSid = L.euSid AND L.pid = P.pid) Order By [Store!1!id] (Select 1 as Tag, null as Parent, S.euSid as [Store!1!id], S.name as [Store!1!name!element], null as [Product!2!name!element], null as [Product!2!price!element] From Stores S) Union All (Select 2 as Tag, 1 as Parent, S.euSid as [Store!1!id], null as [Store!1!name!element], P.name as [Product!2!name!element], P.price as [Product!2!name!element] From Stores S, EuSales L, Products P Where S.euSid = L.euSid AND L.pid = P.pid) Order By [Store!1!id]
18
XML Publishing : SQL Server Explicit Mode All column names are legal SQL names –Special form: [tagname!k!something], –Or [tagname!k!something!element] –Or other variations... Hence everything is legal SQL But what does it mean ? Construct the universal table first Then process the table sequentially
19
XML Publishing : SQL Server Explicit Mode TagParentStore!1!idStore!1!name!elementProduct!2!name!elementProduct!2!price!element 1ABCDENicolas 21ABCDESaint Emilion23.99 21ABCDELoire12.99 1FDKLSFNAC 21FDKLSDatabases49.99... Universal table:
20
XML Publishing : SQL Server Explicit Mode Converting universal table to XML: scan each row sequentially let Tag=k –look up only columns with that tag –all are called [tagname!k!something] with the same tagname What happens if one has a different tagname ? –Create an element called tagname Output –Columns become its children Either subelements or attributes if Parent is specified, last element with that tag is the parent otherwise it is a root element
21
XML Publishing : SQL Server Explicit Mode Nicolas Saint Emilion 23.99 Loire 12.99 FNAC... Nicolas Saint Emilion 23.99 Loire 12.99 FNAC...
22
XML Publishing : SQL Server Explicit Mode Seems complex, but also powerful Can construct arbitrarily deeply nested hierarchies –How ? However, they are very, very limited –Why ?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.