Docstoc

ppt

Document Sample
ppt Powered By Docstoc
					    XML AJAX
       and
     ADO.Net
1
         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


2
       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.

3
     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

4
      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.

5
      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”
6
     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
7
      • HTTP
     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.


8
         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)
9
     Two cultures collide
• Web developers (Documents view)
  – Global infrastructure
  – Standards for document retrieval
  – Standards for materializing
    documents
  – Semi-structured data


10
      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
11
        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.



12
     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




13
     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>

14
     Semi-structured Data


               Although both are human-readable (more-
               or-less), there is nothing to assist a software
               program in identifying the structure of the
      <HTML>   data.
      <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>

15
     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
16
     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


17
                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
18
                  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

19
         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

20
      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
21
      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
22
          XML: Basic Syntax
Set nocount on;
SELECT EMPLOYEEID, LASTNAME,
  FIRSTNAME
FROM EMPLOYEES
FOR XML AUTO, ELEMENTS

I’ll discuss this syntax later.



  23
     XML: Basic Syntax




24
     <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.



25
          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
26
 SELECT EMPLOYEEID, LASTNAME, FIRSTNAME
 FROM EMPLOYEES
                  Using the RAW option, the XML content
 FOR XML RAW
                  can be represented as attributes.




27
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.




  28
       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.
29
       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


30
SELECT E.EMPLOYEEID, LASTNAME, ORDERID, CUSTOMERID, SHIPCITY, ORDERDATE
FROM EMPLOYEES E, ORDERS O
WHERE E.EMPLOYEEID = O.EMPLOYEEID AND
ORDERDATE BETWEEN '1997-01-01' AND '1997-01-02'
FOR XML AUTO, ELEMENTS




   31
SELECT E.EMPLOYEEID, LASTNAME, ORDERID, C.CUSTOMERID,
SHIPCITY, COMPANYNAME
FROM EMPLOYEES E, ORDERS O, CUSTOMERS C
WHERE E.EMPLOYEEID = O.EMPLOYEEID AND
      C.CUSTOMERID=O.CUSTOMERID AND
      ORDERDATE BETWEEN '1997-01-01' AND '1997-01-02'
FOR XML AUTO, ELEMENTS




   32
                       XML

• Another example


SET NOCOUNT ON;
SELECT CUSTOMERS.CUSTOMERID, CUSTOMERS.COMPANYNAME,
ORDERS.ORDERID, ORDERS.ORDERDATE,
[ORDER DETAILS].PRODUCTID, [ORDER DETAILS].QUANTITY
FROM CUSTOMERS, ORDERS, [ORDER DETAILS]
WHERE CUSTOMERS.CUSTOMERID=ORDERS.CUSTOMERID AND
      ORDERS.ORDERID=[ORDER DETAILS].ORDERID AND
      ORDERS.ORDERID=10258
FOR XML AUTO, ELEMENTS


33
                            XML
   • So the output…

CUSTOMERID   COMPANYNAME ORDERID ORDERDATE PRODUCTID QUANTITY
----------   ----------- -------- ---------- --------- --------
ERNSH        Ernst Handel 10258 1996-07-17      2       50
ERNSH        Ernst Handel 10258 1996-07-17      5       65
ERNSH        Ernst Handel 10258 1996-07-17      32      6




   • Gets represented as an XML
     document as:

   34
     XML




35
     XML




36
      XML: Basic Syntax
• How to specify relationships?
• Without a DTD, we can use attributes
  to identify PKs and FKs.
• ID and IDREF




37
     <Northwind>
     <E> <EMPLOYEEID ID="1">              Primary Key
         <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>              Foreign Key
              <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>
                                             Empty Element
         </EMPLOYEEID>
              <O>
              <ORDERID>10402</ORDERID>
              <CUSTOMERID>ERNSH</CUSTOMERID>
              <SHIPCITY>Graz</SHIPCITY>
              <ORDERDATE>1997-01-02T00:00:00</ORDERDATE>
              <EMPLOYEEID IDREF="8"/>
              </O>
38   </E>
     </Northwind>
39
          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”/>




40
                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
41
               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



42
<!DOCTYPE Northwind [
       <!ELEMENT Northwind (EMPLOLYEES*)>
       <!ELEMENT EMPLOYEES (EMPLOYEEID, LASTNAME, FIRSTNAME)>
       <!ELEMENT EMPLOYEEID (#PCDATA)>
       <!ELEMENT LASTNAME (#PCDATA)>
       <!ELEMENT FIRSTNAME (#PCDATA)>
]>
<Northwind>                                  The first line denotes the
       <EMPLOYEES>
               <EMPLOYEEID>1</EMPLOYEEID>
                                             root node of the XML
               <LASTNAME>Davolio</LASTNAME> document.
               <FIRSTNAME>Nancy</FIRSTNAME>
       </EMPLOYEES>
                                             The second line specifies
       <EMPLOYEES>                           <Northwind> can have an
               <EMPLOYEEID>2</EMPLOYEEID>
               <LASTNAME>Fuller</LASTNAME>
                                             arbitrary number of
               <FIRSTNAME>Andrew</FIRSTNAME> <EMPLOYEES>.
       </EMPLOYEES>
       <EMPLOYEES>
                                             The third line specifies the
               <EMPLOYEEID>3</EMPLOYEEID>    sub-elements of
               <LASTNAME>Leverling</LASTNAME>
               <FIRSTNAME>Janet</FIRSTNAME>
                                             <EMPLOYEES>
       </EMPLOYEES>                          The remaining lines define
</Northwind>
                                             each sub-element.
           #PCDATA stands for Parsed Character Data.
     43
           All XML content is character string.
                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.




44
                             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>



     45
                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.




46
 <!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>
47
 </Northwind>
48
                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

49
                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


50
                                   Content can easily be
                                   generated from Northwind
                                   database dynamically. But
                                   again, the problem is how to
                                   get this back into the
<HTML>                             database or a different
<BODY>
<H2>Employee List using HTML</H2>  database.
<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>
51
<?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)>      I’ve included a
]>
<Northwind>
                                           reference to an XSL
       <EMPLOYEES>                         stylesheet.
               <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>
52     </EMPLOYEES>
</Northwind>
     The stylesheet transforms
     the XML tree into a table.



53
<?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>


  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">     Define the type of
       <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR>
                           document with an xsl:
       <xsl:for-each select="Northwind/EMPLOYEES">
          <TR>             begin and end tag with
               <TD><xsl:value-of select="EMPLOYEEID"/></TD>
                           a reference to the w3
               <TD><xsl:value-of select="LASTNAME"/></TD>
               <TD><xsl:value-of select="FIRSTNAME"/></TD>
                           reference schema.
          </TR>
       </xsl:for-each>
    </TABLE>
  </BODY>
  </HTML>
</xsl:template>
</xsl:stylesheet>


  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">     Apply template to
       <TR><TD>EMPLOYEEID</TD><TD>LASTNAME</TD><TD>FIRSTNAME</TD></TR>
                           entire document
       <xsl:for-each select="Northwind/EMPLOYEES">
          <TR>             starting with the root
               <TD><xsl:value-of select="EMPLOYEEID"/></TD>
                           node.
               <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>


  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>
                                 Hard code the basic
               <TD><xsl:value-of select="LASTNAME"/></TD>
               <TD><xsl:value-of select="FIRSTNAME"/></TD>
                                 structure of the table.
          </TR>
       </xsl:for-each>           This could be done in
    </TABLE>                     steps. The heading
  </BODY>
  </HTML>                        values could be
</xsl:template>                  retrieved using the
</xsl:stylesheet>
                                xsl:ELEMENT.
  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> Scroll through each element in the tree starting with the
         “Northwind/EMPLOYEES” Transformation</TITLE></HEAD>
  <HEAD><TITLE>Employee List using XSLsub-elements. For each
  <BODY>
         sub-element, create a row and column in the table.
    <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>


  58
                 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)
59
        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 ON
SELECT PRODUCTID, PRODUCTNAME, UNITSINSTOCK
FROM PRODUCTS
WHERE CATEGORYID=4
FOR XML AUTO, ELEMENTS




60
                              XML
 • We can create an XML document for
   the Product table for all products in
   category 4.
PRODUCTID     PRODUCTNAME                                UNITSINSTOCK
-----------   ----------------------------------------   ------------
11            Queso Cabrales                             22
12            Queso Manchego La Pastora                  86
31            Gorgonzola Telino                          0
32            Mascarpone Fabioli                         9
33            Geitost                                    112
59            Raclette Courdavault                       79
60            Camembert Pierrot                          19
69            Gudbrandsdalsost                           26
71            Flotemysost                                26
72            Mozzarella di Giovanni                     14

 61
     XML




62
                         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 ON
DECLARE @hdoc int
DECLARE @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
  63
                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.
64
                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?




65
               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
66
     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




67
           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


68
 Does XML provide a reasonable
          solution?
• Web developers        •   Database view
  (Documents view)           – Storage techniques
   – Global                  – Standard query language
     infrastructure          – Efficient access to large
   – Standards for             collections of highly
     document retrieval        structured data
                             – Data models for
   – Standards for
                               structuring data
     materializing
     documents               – Mechanisms for
                               maintaining data
   – Semi-structured           integrity and
     data                      consistency
69

				
DOCUMENT INFO