XML AJAX and ADO.Net
description
Transcript of XML AJAX and ADO.Net
![Page 1: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/1.jpg)
1
XML AJAX and
ADO.Net
![Page 2: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/2.jpg)
2
XML: the big picture
• Be wary…• _______ changes EVERYTHING!• Or _______ is a Paradigm Shift!• For the last few years, technology pundits
have XML in the blank.
• Microsoft is pushing XAML as part of the next version of Windows OS– Extensible Application Markup Language– http://msdn2.microsoft.com/en-us/library/ms752059.aspx
![Page 3: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/3.jpg)
3
AJAX: the big picture
• Be wary…• _______ changes EVERYTHING!• Or _______ is a Paradigm Shift!• For the last few years, technology
pundits have AJAX in the blank.
• The main purpose of AJAX appears to be to bring web applications closer to the richness of interaction available to desktop applications.
![Page 4: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/4.jpg)
4
AJAX: the big picture
• The primary “trick” which pulls this off is an asynchronous connection with the web server
• Remember, the web is a stateless environment (or at least the protocols are…)
• This separate communication line allows for “partial” updates and data transfer
![Page 5: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/5.jpg)
5
AJAX: the big picture
• Partial updates require:– A means of identifying parts of a page or
more specifically a document: DOM– A standard way of transferring data to and
from a data source which is compatible with this model: XML
– A standard means of marking up these documents: XSL
– Let’s look at the XML portion first.
![Page 6: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/6.jpg)
6
XML: the big picture
• Two world views: documents/data– Documents: semi-structured– Data: very structured (think ERD)
• The catalyst for convergence– The Internet and WWW
• XML: a data exchange format• Pundits have called this encounter a
“technology train wreck”
![Page 7: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/7.jpg)
7
XML: the big picture
• The WWW defined a simple and universal standard for document exchange (HTML).– Information is decomposed into
named units, marked up, and transmitted•URL•HTML•HTTP
![Page 8: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/8.jpg)
8
XML: the big picture
• The content of these named units of marked up information comes from somewhere…
• Databases!• Generating documents is most
often solved using a three-tier architecture.
![Page 9: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/9.jpg)
9
XML: the big picture
• As an standard, HTML works well for publication, but not so well for data exchange.– Exchange requires screen
scraping and HTML parsing.– http://en.wikipedia.org/wiki/Screen_scraping
– Not a robust solution• XML provides a bridge between
systems (data exchange format)
![Page 10: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/10.jpg)
10
Two cultures collide
• Web developers (Documents view)– Global infrastructure– Standards for document retrieval– Standards for materializing
documents– Semi-structured data
![Page 11: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/11.jpg)
11
Two cultures collide
• Database view– Storage techniques– Standard query language– Efficient access to large
collections of highly structured data
– Data models for structuring data– Mechanisms for maintaining data
integrity and consistency
![Page 12: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/12.jpg)
12
XML: the basics
• A caveat: XML is a VERY large (and often confusing) collection of emerging standards. – Our focus is on the convergence,
that is, the relation of XML to databases.
![Page 13: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/13.jpg)
13
Semi-structured Data
• HTML describes how to present or render the content of an HTML document, that is the structure of the document.
• For example
![Page 14: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/14.jpg)
14
Semi-structured Data
<HTML><BODY><TABLE BORDER=1><TR><TD>1</TD><TD>Davolio</TD><TD>Nancy</TD></TR><TR><TD>1</TD><TD>Fuller</TD><TD>Andrew</TD></TR><TR><TD>1</TD><TD>Leverling</TD><TD>Janet</TD></TR></TABLE></BODY></HTML>
![Page 15: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/15.jpg)
15
Semi-structured Data
<HTML><BODY><TABLE BORDER=1><TR><TD>1</TD><TD>Davolio</TD><TD>Nancy</TD></TR><TR><TD>1</TD><TD>Fuller</TD><TD>Andrew</TD></TR><TR><TD>1</TD><TD>Leverling</TD><TD>Janet</TD></TR></TABLE></BODY></HTML>
Although both are human-readable (more-or-less), there is nothing to assist a software program in identifying the structure of the data.
![Page 16: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/16.jpg)
16
Semi-structured Data
• HTML describes the structure of the document, but what is needed is the structure of the data.
• XML separates– Document structure (DTD)– Content (Elements, Attributes)– Materialization (XSL)
• In HTML, these are confounded
![Page 17: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/17.jpg)
17
Semi-structured Data
• This confounding doesn’t matter for rendering and printing
• A problem arises when developers try to use these rendered documents to electronically exchange data– A natural extension of the analog
world really
![Page 18: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/18.jpg)
18
XML • Moving from semi-structured data
to structured data and back again requires an abstraction of what a document contains– For example, online resume
system for Career Services– Abstract but specific to domain
• But abstraction isn’t enough– Documents must also follow rules
![Page 19: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/19.jpg)
19
XML
• The idea of XML is that a document is defined by it’s structure, not by it’s formatting– Formatting is specific to
application or interface– Document structure defines the
data
![Page 20: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/20.jpg)
20
XML: Basic Syntax• Elements
– A piece of text bounded by matching tags•<employee>Harold</employee>
•<element>content</element>– Elements (tags) can be anything– Elements can contain elements
as well as content
![Page 21: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/21.jpg)
21
XML: Basic Syntax• Sub-elements
<EMPLOYEES><EMPLOYEEID>1</EMPLOYEEID><LASTNAME>Davolio</LASTNAME><FIRSTNAME>Nancy</FIRSTNAME>
</EMPLOYEES>
EmployeeID, LastName, and FirstName are sub-elements of Employee
![Page 22: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/22.jpg)
22
XML: Basic Syntax• Sub-elements
– Describe the relation between an element and its component elements
– An Employee has an id, last name, and first name.
– The query analyzer in SQL Server will create this structure from a query
![Page 23: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/23.jpg)
23
XML: Basic Syntax
Set nocount on;
SELECT EMPLOYEEID, LASTNAME, FIRSTNAME
FROM EMPLOYEES
FOR XML AUTO, ELEMENTS
I’ll discuss this syntax later.
![Page 24: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/24.jpg)
24
XML: Basic Syntax
![Page 25: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/25.jpg)
25
<HTML><BODY><TABLE BORDER=1><TR><TD>1</TD><TD>Davolio</TD><TD>Nancy</TD></TR><TR><TD>1</TD><TD>Fuller</TD><TD>Andrew</TD></TR><TR><TD>1</TD><TD>Leverling</TD><TD>Janet</TD></TR></TABLE></BODY></HTML>
Although the HTML and XML documents contain the same content, the HTML document describes how to present the data. The XML document describes the structure of the data.
![Page 26: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/26.jpg)
26
XML: Basic Syntax• Attributes• XML allows the developer to
associate name/value pairs with an element.– Attributes can contain metadata about the
element or the content itself.– The current thinking seems to be that
elements should contain content and attributes should contain metadata.
– Page 457
![Page 27: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/27.jpg)
27
SELECT EMPLOYEEID, LASTNAME, FIRSTNAMEFROM EMPLOYEESFOR XML RAW
Using the RAW option, the XML content can be represented as attributes.
![Page 28: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/28.jpg)
28
In this case, I’ve include the data type of the element. Go to http://www.w3.org/2001/XMLSchema.xsd for the current standards.
![Page 29: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/29.jpg)
29
XML: Basic Syntax• If the tags are balanced (match) and the
attributes are unique the XML document is said to be well-formed.– However, all this constraint ensures is
that the XML document will parse into a labeled tree.
– Is that sufficient for data exchange?– No.
• But first, let’s look at some more basic structure.
![Page 30: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/30.jpg)
30
XML: Basic Syntax• The preceding example came from
just one table: Employees.• Most transactions will involve
multiple tables.• How are multiple tables
represented?– A tree– A graph
![Page 31: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/31.jpg)
31
SELECT E.EMPLOYEEID, LASTNAME, ORDERID, CUSTOMERID, SHIPCITY, ORDERDATEFROM EMPLOYEES E, ORDERS OWHERE E.EMPLOYEEID = O.EMPLOYEEID AND ORDERDATE BETWEEN '1997-01-01' AND '1997-01-02'FOR XML AUTO, ELEMENTS
![Page 32: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/32.jpg)
32
SELECT E.EMPLOYEEID, LASTNAME, ORDERID, C.CUSTOMERID, SHIPCITY, COMPANYNAMEFROM EMPLOYEES E, ORDERS O, CUSTOMERS CWHERE E.EMPLOYEEID = O.EMPLOYEEID AND C.CUSTOMERID=O.CUSTOMERID AND ORDERDATE BETWEEN '1997-01-01' AND '1997-01-02'FOR XML AUTO, ELEMENTS
![Page 33: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/33.jpg)
33
XML
• Another example
SET NOCOUNT ON;SELECT CUSTOMERS.CUSTOMERID, CUSTOMERS.COMPANYNAME, ORDERS.ORDERID, ORDERS.ORDERDATE, [ORDER DETAILS].PRODUCTID, [ORDER DETAILS].QUANTITYFROM CUSTOMERS, ORDERS, [ORDER DETAILS]WHERE CUSTOMERS.CUSTOMERID=ORDERS.CUSTOMERID AND ORDERS.ORDERID=[ORDER DETAILS].ORDERID AND ORDERS.ORDERID=10258FOR XML AUTO, ELEMENTS
![Page 34: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/34.jpg)
34
XML • So the output…
• Gets represented as an XML document as:
CUSTOMERID COMPANYNAME ORDERID ORDERDATE PRODUCTID QUANTITY ---------- ----------- -------- ---------- --------- -------- ERNSH Ernst Handel 10258 1996-07-17 2 50ERNSH Ernst Handel 10258 1996-07-17 5 65ERNSH Ernst Handel 10258 1996-07-17 32 6
![Page 35: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/35.jpg)
35
XML
![Page 36: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/36.jpg)
36
XML
![Page 37: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/37.jpg)
37
XML: Basic Syntax• How to specify relationships?• Without a DTD, we can use
attributes to identify PKs and FKs.• ID and IDREF
![Page 38: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/38.jpg)
38
<Northwind><E> <EMPLOYEEID ID="1"> <LASTNAME>Davolio</LASTNAME> </EMPLOYEEID>
<O><ORDERID>10400</ORDERID><CUSTOMERID>EASTC</CUSTOMERID><SHIPCITY>London</SHIPCITY><ORDERDATE>1997-01-01T00:00:00</ORDERDATE><EMPLOYEEID IDREF="1"/></O><O><ORDERID>10401</ORDERID><CUSTOMERID>RATTC</CUSTOMERID><SHIPCITY>Albuquerque</SHIPCITY><ORDERDATE>1997-01-01T00:00:00</ORDERDATE><EMPLOYEEID IDREF="1"/></O>
</E><E> <EMPLOYEEID ID="8"> <LASTNAME>Callahan</LASTNAME> </EMPLOYEEID>
<O><ORDERID>10402</ORDERID><CUSTOMERID>ERNSH</CUSTOMERID><SHIPCITY>Graz</SHIPCITY><ORDERDATE>1997-01-02T00:00:00</ORDERDATE><EMPLOYEEID IDREF="8"/></O>
</E></Northwind>
Primary Key
Foreign Key
Empty Element
![Page 39: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/39.jpg)
39
![Page 40: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/40.jpg)
40
XML: Basic Syntax• ID and IDREF can be used to
represent graphs– ERDs
• Minimum and maximum cardinalities can be defined– <EMPLOYEEID IDREF="1“ maxOccurs = “unbounded”/>
![Page 41: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/41.jpg)
41
XML • But again, is it sufficient for an XML
document to well-formed?• No, we have to validate the data
conforms to the structure.• In databases we have mechanisms
for maintaining integrity and consistency.
• In XML, the mechanisms are– Document Type Definition (DTD)– XML Schema
![Page 42: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/42.jpg)
42
DTD• The DTD serves as a grammar for
the underlying XML document– identifies the root document tag– declares what tags are permitted– the structure of the tags– the relations among tags
![Page 43: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/43.jpg)
43
<!DOCTYPE Northwind [<!ELEMENT Northwind (EMPLOLYEES*)><!ELEMENT EMPLOYEES (EMPLOYEEID, LASTNAME, FIRSTNAME)><!ELEMENT EMPLOYEEID (#PCDATA)><!ELEMENT LASTNAME (#PCDATA)><!ELEMENT FIRSTNAME (#PCDATA)>
]><Northwind>
<EMPLOYEES><EMPLOYEEID>1</EMPLOYEEID><LASTNAME>Davolio</LASTNAME><FIRSTNAME>Nancy</FIRSTNAME>
</EMPLOYEES><EMPLOYEES>
<EMPLOYEEID>2</EMPLOYEEID><LASTNAME>Fuller</LASTNAME><FIRSTNAME>Andrew</FIRSTNAME>
</EMPLOYEES><EMPLOYEES>
<EMPLOYEEID>3</EMPLOYEEID><LASTNAME>Leverling</LASTNAME><FIRSTNAME>Janet</FIRSTNAME>
</EMPLOYEES></Northwind>
The first line denotes the root node of the XML document.The second line specifies <Northwind> can have an arbitrary number of <EMPLOYEES>.The third line specifies the sub-elements of <EMPLOYEES>The remaining lines define each sub-element. #PCDATA stands for Parsed Character Data.
All XML content is character string.
![Page 44: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/44.jpg)
44
DTD• The order of elements in the <!
Element > tag are meaningful.• To be validated, the tags in the
XML document must conform to the order specified in the DTD.
![Page 45: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/45.jpg)
45
DTD <!DOCTYPE Orderlist [ <!ELEMENT Orderlist (Customers)> <!ELEMENT Customers (CustomerID, CompanyName, Orders)>
<!ELEMENT CustomerID (#PCDATA)> <!ELEMENT CompanyName (#PCDATA)><!ELEMENT Orders (OrderID, OrderDate,ORDER_x0020_DETAILS)>
<!ELEMENT OrderID (#PCDATA)><!ELEMENT OrderDate (#PCDATA)>
<!ELEMENT Orders_x0020_DETAILS (ProductID, Quantity)><!ELEMENT ProductID (#PCDATA)><!ELEMENT Quantity (#PCDATA)>
]><ORDERLIST><CUSTOMERS>stuff…</CUSTOMERS></ORDERLIST>
![Page 46: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/46.jpg)
46
DTD• We specify relationships with ID
and IDREF but in the <!ATTLIST > tag.
• The <!ATTLIST > tag allows us to assert specifics about the type of the attribute.
![Page 47: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/47.jpg)
47
<!DOCTYPE Northwind [<!ELEMENT Northwind (E*)><!ELEMENT EMPLOYEES (EMPLOYEEID, LASTNAME, O)> <!ATTLIST E EMPLOYEEID ID #REQUIRED><!ELEMENT EMPLOYEEID (#PCDATA)><!ELEMENT LASTNAME (#PCDATA)><!ELEMENT O (ORDERID, CUSTOMERID, SHIPCITY, ORDERDATE, EMPLOYEEID)><!ELEMENT ORDERID (#PCDATA)><!ELEMENT SHIPCITY (#PCDATA)><!ELEMENT ORDERDATE (#PCDATA)><!ELEMENT EMPLOYEEID (#PCDATA)> <!ATTLIST E EMPLOYEEID IDREF #REQUIRED>
]><Northwind><E><EMPLOYEEID>1</EMPLOYEEID><LASTNAME>Davolio</LASTNAME>
<O><ORDERID>10400</ORDERID><CUSTOMERID>EASTC</CUSTOMERID><SHIPCITY>London</SHIPCITY><ORDERDATE>1997-01-01T00:00:00</ORDERDATE><EMPLOYEEID>1</EMPLOYEEID></O><O><ORDERID>10401</ORDERID><CUSTOMERID>RATTC</CUSTOMERID><SHIPCITY>Albuquerque</SHIPCITY><ORDERDATE>1997-01-01T00:00:00</ORDERDATE><EMPLOYEEID>1</EMPLOYEEID></O>
</E><E><EMPLOYEEID>8</EMPLOYEEID><LASTNAME>Callahan</LASTNAME>
<O><ORDERID>10402</ORDERID><CUSTOMERID>ERNSH</CUSTOMERID><SHIPCITY>Graz</SHIPCITY><ORDERDATE>1997-01-02T00:00:00</ORDERDATE<EMPLOYEEID>8</EMPLOYEEID></O>
</E></Northwind>
![Page 48: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/48.jpg)
48
![Page 49: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/49.jpg)
49
XSL• XML separates
– Document structure (DTD)– Content (Elements, Attributes)– Materialization (XSL)
• XSL transforms XML into HTML• The data model for XSL is an
ordered tree
![Page 50: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/50.jpg)
50
XSL• XSL is defined as a set of template
rules• Each rule consists of a pattern and
a template• Transformation syntax permits
conversion of labeled tree into HTML
• For example
![Page 51: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/51.jpg)
51
<HTML><BODY><H2>Employee List using HTML</H2><TABLE BORDER="1"><TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR><TR><TD>1</TD><TD>Davolio</TD><TD>Nancy</TD></TR><TR><TD>2</TD><TD>Fuller</TD><TD>Andrew</TD></TR><TR><TD>3</TD><TD>Leverling</TD><TD>Janet</TD></TR></TABLE></BODY></HTML>
Content can easily be generated from Northwind database dynamically. But again, the problem is how to get this back into the database or a different database.
![Page 52: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/52.jpg)
52
<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="employeesDTD.xsl"?>
<!DOCTYPE Northwind [<!ELEMENT Northwind (EMPLOLYEES*)><!ELEMENT EMPLOYEES (EMPLOYEEID, LASTNAME, FIRSTNAME)><!ELEMENT EMPLOYEEID (#PCDATA)><!ELEMENT LASTNAME (#PCDATA)><!ELEMENT FIRSTNAME (#PCDATA)>
]><Northwind>
<EMPLOYEES><EMPLOYEEID>1</EMPLOYEEID><LASTNAME>Davolio</LASTNAME><FIRSTNAME>Nancy</FIRSTNAME>
</EMPLOYEES><EMPLOYEES>
<EMPLOYEEID>2</EMPLOYEEID><LASTNAME>Fuller</LASTNAME><FIRSTNAME>Andrew</FIRSTNAME>
</EMPLOYEES><EMPLOYEES>
<EMPLOYEEID>3</EMPLOYEEID><LASTNAME>Leverling</LASTNAME><FIRSTNAME>Janet</FIRSTNAME>
</EMPLOYEES></Northwind>
I’ve included a reference to an XSL stylesheet.
![Page 53: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/53.jpg)
53
The stylesheet transforms the XML tree into a table.
![Page 54: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/54.jpg)
54
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <HTML> <HEAD><TITLE>Employee List using XSL Transformation</TITLE></HEAD> <BODY> <H2>Employee List using XSL Transformation</H2> <TABLE BORDER="1"> <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR> <xsl:for-each select="Northwind/EMPLOYEES"> <TR> <TD><xsl:value-of select="EMPLOYEEID"/></TD> <TD><xsl:value-of select="LASTNAME"/></TD> <TD><xsl:value-of select="FIRSTNAME"/></TD> </TR> </xsl:for-each> </TABLE> </BODY> </HTML></xsl:template></xsl:stylesheet>
![Page 55: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/55.jpg)
55
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <HTML> <HEAD><TITLE>Employee List using XSL Transformation</TITLE></HEAD> <BODY> <H2>Employee List using XSL Transformation</H2> <TABLE BORDER="1"> <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR> <xsl:for-each select="Northwind/EMPLOYEES"> <TR> <TD><xsl:value-of select="EMPLOYEEID"/></TD> <TD><xsl:value-of select="LASTNAME"/></TD> <TD><xsl:value-of select="FIRSTNAME"/></TD> </TR> </xsl:for-each> </TABLE> </BODY> </HTML></xsl:template></xsl:stylesheet>
Define the type of document with an xsl: begin and end tag with a reference to the w3 reference schema.
![Page 56: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/56.jpg)
56
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <HTML> <HEAD><TITLE>Employee List using XSL Transformation</TITLE></HEAD> <BODY> <H2>Employee List using XSL Transformation</H2> <TABLE BORDER="1"> <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR> <xsl:for-each select="Northwind/EMPLOYEES"> <TR> <TD><xsl:value-of select="EMPLOYEEID"/></TD> <TD><xsl:value-of select="LASTNAME"/></TD> <TD><xsl:value-of select="FIRSTNAME"/></TD> </TR> </xsl:for-each> </TABLE> </BODY> </HTML></xsl:template></xsl:stylesheet>
Apply template to entire document starting with the root node.
![Page 57: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/57.jpg)
57
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <HTML> <HEAD><TITLE>Employee List using XSL Transformation</TITLE></HEAD> <BODY> <H2>Employee List using XSL Transformation</H2> <TABLE BORDER="1"> <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR> <xsl:for-each select="Northwind/EMPLOYEES"> <TR> <TD><xsl:value-of select="EMPLOYEEID"/></TD> <TD><xsl:value-of select="LASTNAME"/></TD> <TD><xsl:value-of select="FIRSTNAME"/></TD> </TR> </xsl:for-each> </TABLE> </BODY> </HTML></xsl:template></xsl:stylesheet>
Hard code the basic structure of the table. This could be done in steps. The heading values could be retrieved using the xsl:ELEMENT.
![Page 58: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/58.jpg)
58
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <HTML> <HEAD><TITLE>Employee List using XSL Transformation</TITLE></HEAD> <BODY> <H2>Employee List using XSL Transformation</H2> <TABLE BORDER="1"> <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR> <xsl:for-each select="Northwind/EMPLOYEES"> <TR> <TD><xsl:value-of select="EMPLOYEEID"/></TD> <TD><xsl:value-of select="LASTNAME"/></TD> <TD><xsl:value-of select="FIRSTNAME"/></TD> </TR> </xsl:for-each> </TABLE> </BODY> </HTML></xsl:template></xsl:stylesheet>
Scroll through each element in the tree starting with the “Northwind/EMPLOYEES” sub-elements. For each sub-element, create a row and column in the table.
![Page 59: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/59.jpg)
59
XSL• I embedded the DTD in the XML
document, but if I had stored it as a separate file, the Employee List materialization would involve three distinct files
• Employees.xml (content)• Employees.dtd (structure)• Employees.xsl (presentation)
![Page 60: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/60.jpg)
60
XML: data exchange • We can create an XML document
for the Product table for all products in category 4 that can be imported into the database.
SET NOCOUNT ONSELECT PRODUCTID, PRODUCTNAME, UNITSINSTOCK FROM PRODUCTS WHERE CATEGORYID=4FOR XML AUTO, ELEMENTS
![Page 61: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/61.jpg)
61
XML • We can create an XML document
for the Product table for all products in category 4.
PRODUCTID PRODUCTNAME UNITSINSTOCK ----------- ---------------------------------------- ------------ 11 Queso Cabrales 2212 Queso Manchego La Pastora 8631 Gorgonzola Telino 032 Mascarpone Fabioli 933 Geitost 11259 Raclette Courdavault 7960 Camembert Pierrot 1969 Gudbrandsdalsost 2671 Flotemysost 2672 Mozzarella di Giovanni 14
![Page 62: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/62.jpg)
62
XML
![Page 63: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/63.jpg)
63
XML • This XML can then be parsed and
used by the DBMS. In this case, to insert the records into the local database.
SET NOCOUNT ONDECLARE @hdoc intDECLARE @doc varchar(4000)SET @doc ='<P><PRODUCTS><PRODUCTID>11</PRODUCTID>stuff…</ROOT>'EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc
SELECT * INTO ProductListCategory4 FROM OPENXML (@hdoc, '/P/PRODUCTS',2) WITH (PRODUCTID int, PRODUCTNAME varchar(25), UNITSINSTOCK int)EXEC sp_xml_removedocument @hdoc
![Page 64: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/64.jpg)
64
XML • Sp_xml_preparedocument is a
system stored procedure that creates an internal tree representation of the XML document that can then be represented as a cursor or table using OPENXML.
• OPENXML creates a cursor or rowset representation that can then me used in a SQL expression.
• Sp_xml_removedocument clears the rows et from memory.
![Page 65: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/65.jpg)
65
XML • Returning to the original claim that
XML will change everything• How is XML an improvement over
say SQL Server’s DTS?• Saving as comma delimited flat
file?
![Page 66: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/66.jpg)
66
XML • XML is a language for manipulating
the what rather the how of data.• Standard means for representing
domains• Standard means of expressing
views• Clean separation of structure,
content, and formatting• Facility for document validity
checking
![Page 67: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/67.jpg)
67
Extensible Style Language Transformation –XMLT
• XMLT is used to transform one document into another document
• Mapping company A’s document (say an order) into company B’s DTD or schema
![Page 68: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/68.jpg)
68
XML Schema
• XML Schema is the preferred method for defining document structure
• The schema itself is an XML document• A document that conforms to an XML
Schema is termed schema-valid.• XML Schema documents are validated
against the root schema at www.w3.org
![Page 69: XML AJAX and ADO.Net](https://reader035.fdocuments.us/reader035/viewer/2022062315/56815563550346895dc32d78/html5/thumbnails/69.jpg)
69
Does XML provide a reasonable solution?
• Web developers (Documents view)– Global
infrastructure– Standards for
document retrieval
– Standards for materializing documents
– Semi-structured data
• Database view– Storage techniques– Standard query
language– Efficient access to large
collections of highly structured data
– Data models for structuring data
– Mechanisms for maintaining data integrity and consistency