Download presentation
Presentation is loading. Please wait.
1
Chapter 1 XML Design for Data
Database Lab 석사1학기 강 나 영
2
XML for Text vs.XML for Data
If the markup were removed, the text of paragraph itself would still have the same meaning outside the XML document. The order of the information is of critical importance to understanding its meaning. XML for Data Data can be represented in a number of different ways and still have the same functionality.
3
Representing Data in XML
Element Content Models Element-only content Mixed content Text-only content The EMPTY model The Ant model Using Attributes Other Considerations Audience Performance Data modeling vs. representation modeling
4
Element Content Models(1)
Element-only content Elements may only contain other elements. ex) Mixed Content Elements may contain zero or more instances of list of elements. <!ELEMENT Invoice (Customer, LineItem+)> <Invoice> <Customer /> <LineItem /> </Invoice> <!ELEMENT Invoice (#PCDATA | LineItem | Custome)*> <Invoice> This is the invoice for <Customer>Kevin Williams</Customer> </Invoice>
5
Element Content Models(2)
Text-only Content Elements may only contain text string. ex) One way to include data points in our documents. EMPTY Content An element cannot contain anything at all. <!ELEMENT Customer (#PCDATA)> <Customer>Kevin Williams</Customer> <!ELEMENT Customer EMPTY> <Customer />
6
Element Content Models(3)
ANY Content Any element or text may appear inside the element. ex) or ※Mixed content model & ANY content model ; too permissive for data <!ELEMENT Customer ANY> <Customer>Kevin Williams</Customer> <Customer> <Customer>Kevin Williams</Customer> </Customer>
7
Using Attributes The other way to represent data points. ex)
<!ELEMENT Customer EMPTY> <!ATTLIST Customer FirstName CDATA #REQUIRED LastName CDATA #REQUIRED> <Customer FirstName=“Kevin” LastName=“Williams”/>
8
Other Considerations(1)
Audience Dose the document need to be human-readable? Is the document intended primarily for display or for processing? How many consumers will be processing the document? Is the document intended to operate under a standard that constrains the allowable structure? Performance ex) <Invoice customerName=“Kevin Williams”> <LineItem productName=“Grommets (2 inch)” quantity=“17” price=“0.10” /></Invoice> <I c=“c17”><L p=“p22” q=“17” pr=“.1” /></I>
9
Other Considerations(2)
Data Modeling vs. Representation Modeling Representation Modeling ex) <Invoice> Widgets, Inc. Invoice Customer: <customerName>Kevin Williams</customerName> <orderAddress>742 Evergreen Terrace</orderAddress> Ship to: <shipName>Kevin Williams</shipName> <shipAddress>742 Evergreen Terrace</shipAddress> Shipper: <shippingCompany>FedEx</shoppingCompany> Item Code Description Quantity price Total <LineItem> <itemCode>1A2A3AB</itemCode> <itemDescription>Widget(3 inch)</itemDescription> <quantity>17</quantity> <price>$0.10</price> <linePrice>$1.70</linePrice> </LineItem> </Invoice>
10
Other Considerations(2)
Data Modeling vs. Representation Modeling Data Modeling ex) <Invoice customerName=“Kevin Williams” <Address addressType=“billing” street=“742 Evergreen Terrace”/> addressType=“shipping” <LineItem itemCode=“1A2A3AB” itemDescription=“Widget(3 inch)” quantity=“17” price=“0.10” currency=“USD”/> </Invoice>
11
Mapping Between RDBMS and XML Structures(1)
When moving data between XML form and a relational database a table ↔ an element with element-only content ex) Within <Customer> element, the details about the customer can be represented in one of two ways. Using text-only elements. Using attributes. CREATE TABLE Customer ( firstName varchar(50), lastName varchar(50), mailingAddress varchar(50), mailingCity varchar(60), mailingState varchar(3))
12
Mapping Between RDBMS and XML Structures(2)
1) Elements ex) <!ELEMENT Customer (firstName, lastName, mailingAddress, mailingCity, mailingState)> <!ELEMENT firstName (#PCDATA)> <!ELEMENT lastName (#PCDATA)> <!ELEMENT mailingAddress (#PCDATA)> ‥‥ <Customer> <firstName>Kevin</firstName> <lastName>Williams</lastName> <mailingAddress>742 Evergreen Terrace</mailingAddress> ‥‥ </Customer> When representing data in an XML document, any element that is defined as having text-only content using the #PCDATA keyword will correspond to a column in a relational database.
13
Mapping Between RDBMS and XML Structures(3)
2) Attributes Elements that represent tables have attributes associated with them that represent columns. ex) <!ELEMENT Customer EMPTY> <!ATTRIST Customer firstName CDATA #REQUIRED lastName CDATA #REQUIRED mailingAddress CDATA #REQUIRED ‥‥ <Customer firstName=“Kevin” lastName=“Williams” mailingAddress=“742 Evergreen Terrace” ‥‥ />
14
Mapping Between RDBMS and XML Structures(4)
Data Points There are two primary design strategies that may be used to represent column s as XML structures. Elements, which are nested as children of the element that represents the grouping of information. Attributes, which are added to the element that represents the grouping of information. ex) Widgets, Inc. Invoice Customer: Kevin Williams 742 Evergreen Terrace Ship to: Kevin Williams Shipper: FedEx Item Code Description Quantity price Total 1A2A3AB Widget(3 inch) $ $1.70
15
Mapping Between RDBMS and XML Structures(5)
1) Our Invoice Using Elements ex) <!ELEMENT Invoice (customerName, billingAddress, billingCity, billingState, ‥‥, LineItem+)> <!ELEMENT customerName (#PCDAYA)> <!ELEMENT billingAddress (#PCDATA)> ‥‥ <!ELEMENT LineItem (itemCode, itemDescription,quantity,price)> <!ELEMENT itemCode (#PCDATA)> <!ELEMENT itemDescription (#PCDATA)> [Ch02_ex1.dtd] <?xml version=“1.0” ?> <!DOCTYPE Invoice SYSTEM <Invoice> <customerName>Kevin Williams</customerName> ‥‥ <LineItem> <itemCode>1A2A3AB</itemCode> [Ch02_ex1.xml]
16
Mapping Between RDBMS and XML Structures(6)
2) Our Invoice Using Attributes ex) <!ELEMENT Invoive (LineItem+)> <!ATTRIST Invoice customerName CDATA #REQUIRED billingAddress CDATA #REQUIRED ‥‥ > <!ELEMENT LineItem EMPTY> <!ATTRIST Lineitem itemCode CDATA #REQUIRED itemDescription CDATA #REQUIRED [Ch02_ex2.dtd] <?xml version=“1.0” ?> <!DOCTYPE Invoice SYSTEM <Invoice customerName=“Kevin Williams” ‥‥ /> <LineItem itemCode=“1A2A3AB” </Invoice> [Ch02_ex2.xml]
17
Mapping Between RDBMS and XML Structures(7)
3) Comparing the two Approaches Readability Compatibility with database Strong data typing Programming complexity DOM (Document object Model) SAX (Simple API for XML) Document size
18
Mapping Between RDBMS and XML Structures(8)
Relationships ex) Invoice LineItem CREATE TABLE Invoice ( invoiceID integer PRIMARY KEY, customerID integer, ‥‥ ) CREATE TABLE LineItem ( lineItem integer, invoiceID integer, ‥‥ CONSTAINT fk_LineItemInvoice FOREIGN KEY (invoiceID) REFERENCES Invoice (invoiceID)) invoiceID customerID orderDate shipDate lineItemID invoiceID productDescription quantity unitprice
19
Mapping Between RDBMS and XML Structures(9)
1) Containment One-to-one and one-to-many relationships are best represented by containment ex) <!ELEMENT Invoive (LineItem+)> <!ATTRIST Invoice orderDate CDATA #REQUIRED shipDate CDATA #REQUIRED> <!ELEMENT LineItem EMPTY> <!ATTRIST Lineitem productDescription CDATA #REQUIRED ‥‥ >
20
Mapping Between RDBMS and XML Structures(10)
2) More Complex Relationships - Pointers Invoice invoiceID customerID orderDate shipDate LineItem lineItemID invoiceID productID quantity unitprice Product productID productShortName productDescription
21
Mapping Between RDBMS and XML Structures(11)
2) More Complex Relationships - Pointers ex) ch02_ex3.dtd <!ELEMENT orderData (Invoice+, Product+)> <!ELEMENT Invoive (LineItem+)> <!ATTRIST Invoice orderDate CDATA #REQUIRED shipDate CDATA #REQUIRED> <!ELEMENT LineItem EMPTY> <!ATTRIST Lineitem productIDREF IDREF #REQUIRED ‥‥ > <!ELEMENT Product EMPTY> <!ATTRIST Product productID ID #REQUIRED
22
Mapping Between RDBMS and XML Structures(12)
ex) ch02_ex3.xml <?xml version=“1.0” ?> <!DOCTYPE Invoice SYSTEM <orderData> <Invoice orderDate=“7/23/2000” shipData=“7/28/2000”> <LineItem productIDREF=“prod1” ‥‥ /> /Invoice> ‥‥ <Product productID=“prod1” productShortName=“Widgets (3 inch)” </orderData>
23
Mapping Between RDBMS and XML Structures(13)
3) More Complex Relationships - Contianments ex) ch02_ex4.dtd <!ELEMENT orderData (Invoice+)> <!ELEMENT Invoive (LineItem+)> <!ATTRIST Invoice orderDate CDATA #REQUIRED shipDate CDATA #REQUIRED> <!ELEMENT LineItem (Product)> <!ATTRIST Lineitem quantity CDATA #REQUIRED ‥‥ > <!ELEMENT Product EMPTY> <!ATTRIST Product productShortName CDATA #REQUIRED
24
Mapping Between RDBMS and XML Structures(14)
ex) ch02_ex4.xml <?xml version=“1.0” ?> <!DOCTYPE Invoice SYSTEM <orderData> <Invoice orderDate=“7/23/2000” shipData=“7/28/2000”> <LineItem quantity=“17” uniPrice=“0.10”> <Product productShortName=“Widgets (3 inch)” ‥‥ /> </LineItem> </Invoice> ‥‥ </orderData>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.