Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 434 Advanced Database Systems

Similar presentations

Presentation on theme: "ICS 434 Advanced Database Systems"— Presentation transcript:

1 ICS 434 Advanced Database Systems
Dr. Abdallah Al-Sukairi Second Semester (032) King Fahd University of Petroleum & Minerals Information & Computer Science Department

2 Introduction to XML

3 What is XML? XML stands for EXtensible Markup Language
A meta-language for descriptive markup: you invent your own tags XML uses a Document Type Definition (DTD) or an XML Schema to describe the data XML with a DTD or XML Schema is designed to be self-descriptive Built-in internationalization via Unicode Built-in error-handling Optimized for network operations Tons of support from the big IT companies

4 Some History SGML (Standard Generalized Markup Language) XML
ISO Standard, 1986, for data storage & exchange Metalanguage for defining languages (through DTDs) A famous SGML language: HTML Separation of content and display Used in U.S. gvt. & contractors, large manufacturing companies, technical info. Publishers,... SGML reference is 600 pages long XML W3C recommendation in 1998 Simple subset (80/20 rule) of SGML: “ASCII of the Web”, “Semantic Web” XML specification is 26 pages long

5 Timeline 1986 SGML becomes a standard 1989 Tim Berners-Lee creates the WWW 1994 W3C established 1998 XML 1.0 W3C Recommendation Jan 2000 XHTML becomes W3C Recommendation A Reformulation of HTML 4 in XML 1.0 Oct 2000 W3c XML 1.0 (Second Edition) Recommendation Oct 2002 XML 1.1 Candidate Recommendation updates XML to use Unicode 3

6 XML and HTML XML is not a replacement for HTML
XML was designed to carry data XML and HTML were designed with different goals XML was designed to describe data and to focus on what data is HTML was designed to display data and to focus on how data looks. HTML is about displaying information, while XML is about describing information

7 HTML and XML, I HTML is used to mark up text so it can be displayed to users XML is used to mark up data so it can be processed by computers HTML describes both structure (e.g. <p>, <h2>, <em>) and appearance (e.g. <br>, <font>, <i>) XML describes only content, or “meaning” HTML uses a fixed, unchangeable set of tags In XML, you make up your own tags

8 HTML and XML, II HTML and XML look similar, because they are both SGML languages Both HTML and XML use elements enclosed in tags Both use tag attributes More precisely, HTML is defined in SGML XML is a (very small) subset of SGML

9 HTML and XML, III HTML is for humans XML is for computers
HTML describes web pages You don’t want to see error messages about the web pages you visit Browsers ignore and/or correct as many HTML errors as they can, so HTML is often sloppy XML is for computers XML describes data The rules are strict and errors are not allowed In this way, XML is like a programming language Current versions of most browsers can display XML

10 XML does not DO anything
XML was not designed to DO anything XML is created to structure, store and to send information The following example is a book info, stored as XML: <?xml version='1.0'?> <bookstore> <book genre=‘autobiography’ publicationdate=‘1981’ ISBN=‘ ’> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> </bookstore>

11 XML is Free and Extensible
XML tags are not predefined You must "invent" your own tags The tags used to mark up HTML documents and the structure of HTML documents are predefined The author of HTML documents can only use tags that are defined in the HTML standard XML allows the author to define his own tags and his own document structure

12 XML Future XML is going to be everywhere
XML is a cross-platform, software and hardware independent tool for transmitting information. XML Application X XML Documents Configuration XML XML Repository Database

13 Benefits of XML Open W3C standard
Representation of data across heterogeneous environments Cross platform Allows for high degree of interoperability Strict rules Syntax Structure Case sensitive

14 How can XML be Used? XML can Separate Data from HTML
With XML, your data is stored outside your HTML XML is used to Exchange Data With XML, data can be exchanged between incompatible systems With XML, financial information can be exchanged over the Internet XML can be used to Share Data XML can be used to Store Data XML can make your Data more Useful XML can be used to Create new Languages

15 Components of an XML Document
Elements Each element has a beginning and ending tag <TAG_NAME>...</TAG_NAME> Elements can be empty (<TAG_NAME />) Attributes Describes an element; e.g. data type, data range, etc. Can only appear on beginning tag Processing instructions Encoding specification (Unicode by default) Namespace declaration Schema declaration

16 Components of an XML Document
<?xml version=“1.0” ?> <?xml-stylesheet type="text/xsl" href=“template.xsl"?> <ROOT> <ELEMENT1><SUBELEMENT1 /><SUBELEMENT2 /></ELEMENT1> <ELEMENT2> </ELEMENT2> <ELEMENT3 type=‘string’> </ELEMENT3> <ELEMENT4 type=‘integer’ value=‘9.3’> </ELEMENT4> </ROOT> Elements with Attributes Elements Processing Instructions

17 XML declaration The XML declaration looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> The XML declaration is not required by browsers, but is required by most XML processors (so include it!) If present, the XML declaration must be first--not even whitespace should precede it Note that the brackets are <? and ?> version="1.0" is required (this is the only version so far) encoding can be "UTF-8" (ASCII) or "UTF-16" (Unicode), or something else, or it can be omitted standalone tells whether there is a separate DTD

18 Processing Instructions
PIs (Processing Instructions) may occur anywhere in the XML document (but usually first) A PI is a command to the program processing the XML document to handle it in a certain way XML documents are typically processed by more than one program Programs that do not recognize a given PI should just ignore it General format of a PI: <?target instructions?> Example: <?xml-stylesheet type="text/css" href="mySheet.css"?>

19 XML Elements An XML element is everything from the element's start tag to the element's end tag XML Elements are extensible and they have relationships XML Elements have simple naming rules Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names must not start with the letters xml (or XML or Xml ..) Names cannot contain spaces

20 XML Attributes XML elements can have attributes
Data can be stored in child elements or in attributes Should you avoid using attributes? Here are some of the problems using attributes: attributes cannot contain multiple values (child elements can) attributes are not easily expandable (for future changes) attributes cannot describe structures (child elements can) attributes are more difficult to manipulate by program code attribute values are not easy to test against a Document Type Definition (DTD) - which is used to define the legal elements of an XML document

21 An XML Document <?xml version='1.0'?> <bookstore>
<book genre=‘autobiography’ publicationdate=‘1981’ ISBN=‘ ’> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre=‘novel’ publicationdate=‘1967’ ISBN=‘ ’> <title>The Confidence Man</title> <first-name>Herman</first-name> <last-name>Melville</last-name> <price>11.99</price> </bookstore>

22 Another XML Document <?xml version="1.0"?> <weatherReport> <date>7/14/97</date> <city>North Place</city>, <state>NX</state> <country>USA</country> High Temp: <high scale="F">103</high> Low Temp: <low scale="F">70</low> Morning: <morning>Partly cloudy, Hazy</morning> Afternoon: <afternoon>Sunny & hot</afternoon> Evening: <evening>Clear and Cooler</evening> </weatherReport>

23 XML Validation XML with correct syntax is Well Formed XML
XML validated against a DTD is Valid XML

24 Rules For Well-Formed XML
There must be one, and only one, root element All XML elements must have a closing tag Sub-elements must be properly nested A tag must end within the tag in which it was started Attributes are optional Defined by an optional schema Attribute values must be enclosed in “” or ‘’ Processing instructions are optional XML is case-sensitive <tag> and <TAG> are not the same type of element White space is preserved CR / LF is converted to LF Comment in XML is similar to that of HTML

25 XML DTD A DTD defines the legal elements of an XML document XML Schema
defines the document structure with a list of legal elements XML Schema  XML Schema is an XML based alternative to DTD Errors in XML documents will stop the XML program XML Validators

26 Browsers Support for XML
Netscape 6 supports XML Internet Explorer 5.0 supports the XML 1.0 standard Internet Explorer 5.0 has the following XML support: Viewing of XML documents Full support for W3C DTD standards XML embedded in HTML as Data Islands Binding XML data to HTML elements Transforming and displaying XML with XSL Displaying XML with CSS Access to the XML DOM

27 Viewing XML Files Raw XML files can be viewed in IE 5.0 (and higher) and in Netscape 6 but to make it display like a web page, you have to add some display information XML documents do not carry information about how to display the data Different solutions to the display problem, using CSS, XSL, JavaScript, and XML Data Islands Will you be writing your future Homepages in XML?

28 Displaying XML with CSS
With CSS (Cascading Style Sheets) you can add display information to an XML document Formatting XML with CSS is NOT the future of the Web Formatting with XSL will be the new standard

29 Example: the xml file <?xml version="1.0" encoding="ISO "?> <?xml-stylesheet type="text/css" href="cd_catalog.css"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG>

30 Example: the css file CATALOG
{ background-color: #ffffff; width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { color: #FF0000; font-size: 20pt; } ARTIST { color: #0000FF; font-size: 20pt; } COUNTRY,PRICE,YEAR,COMPANY { Display: block; color: #000000; margin-left: 20pt; }

31 Displaying XML with XSL
With XSL you can add display information to your XML document XSL is the preferred style sheet language of XML XSL (the eXtensible Stylesheet Language) is far more sophisticated than CS One way to use XSL is to transform XML into HTML before it is displayed by the browser

32 Example: the xml file <?xml version="1.0" encoding="ISO "?> <?xml-stylesheet type="text/xsl" href="simple.xsl" ?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>two of our famous Belgian Waffles with plenty of real maple syrup</description> <calories>650</calories> </food> <name>Strawberry Belgian Waffles</name> <price>$7.95</price> <description>light Belgian waffles covered with strawberries and whipped cream</description> <calories>900</calories> </breakfast_menu>

33 Example: the xsl file <?xml version="1.0" encoding="ISO "?> <html xsl:version="1.0" xmlns:xsl="" xmlns=""> <body style="font-family:Arial,helvetica,sans-serif;font-size:12pt; background-color:#EEEEEE"> <xsl:for-each select="breakfast_menu/food"> <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold;color:white"> <xsl:value-of select="name"/></span> - <xsl:value-of select="price"/> </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> <xsl:value-of select="description"/> <span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving) </span> </xsl:for-each> </body> </html>

34 View the result in IE 6

35 XML Data Islands XML can be embedded within HTML pages in Data Islands
Manipulated via client side script or data binding The unofficial <xml> tag is used to embed XML data within HTML Data Islands can be bound to HTML elements (like HTML tables) <html> <body> <xml id="cdcat" src="cd_catalog.xml"></xml> <table border="1" datasrc="#cdcat"> <tr> <td> <span datafld="ARTIST"> </span> </td> <td> <span datafld="TITLE"> </span> </td> </tr> </table> </body> </html>

36 The Microsoft XML Parser
To read and update an XML document, you need an XML parser The Microsoft XML parser comes with Microsoft Internet Explorer 5.0 Once you have installed IE 5.0, the parser is available to scripts, both inside HTML documents. The parser features a language-neutral programming model that supports: JavaScript, VBScript, Perl, VB, Java, C++ and more W3C XML 1.0 and XML DOM DTD and validation You can create an XML document object with the following code: var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")

37 Loading an XML file into the parser
XML files can be loaded into the parser using script code. The following code loads an XML document (note.xml) into the XML parser: <script type="text/javascript"> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") // processing the document goes here </script> The second line in the code above creates an instance of the Microsoft XML parser The third line turns off asynchronized loading, to make sure that the parser will not continue execution before the document is fully loaded The fourth line tells the parser to load the XML document called note.xml The second line in the code above creates an instance of the Microsoft XML parser. The third line turns off asynchronized loading, to make sure that the parser will not continue execution before the document is fully loaded. The fourth line tells the parser to load the XML document called note.xml.", "width": "800" }

38 Namespaces: Overview Part of XML’s extensibility
Allow authors to differentiate between tags of the same name (using a prefix) Frees author to focus on the data and decide how to best describe it Allows multiple XML documents from multiple authors to be merged Identified by a URI (Uniform Resource Identifier) When a URL is used, it does NOT have to represent a live server URLs and URNs for namespaces do not have to be “live” – they only need to be unique strings.

39 Namespaces: Declaration
Namespace declaration examples: xmlns: bk = “” xmlns: bk = “” xmlns: bk = “” Namespace declaration Prefix URI (URL)

40 Namespaces: Examples <BOOK xmlns:bk=“”> <bk:TITLE>All About XML</bk:TITLE> <bk:AUTHOR>Joe Developer</bk:AUTHOR> <bk:PRICE currency=‘US Dollar’>19.99</bk:PRICE> <bk:BOOK xmlns:bk=“” xmlns:money=“urn:finance:money”> <bk:TITLE>All About XML</bk:TITLE> <bk:AUTHOR>Joe Developer</bk:AUTHOR> <bk:PRICE money:currency=‘US Dollar’> 19.99</bk:PRICE>

41 Namespaces: Default Namespace
An XML namespace declared without a prefix becomes the default namespace for all sub-elements All elements without a prefix will belong to the default namespace: <BOOK xmlns=“”> <TITLE>All About XML</TITLE> <AUTHOR>Joe Developer</AUTHOR>

42 Namespaces: Scope Unqualified elements belong to the inner-most default namespace. BOOK, TITLE, and AUTHOR belong to the default book namespace PUBLISHER and NAME belong to the default publisher namespace <BOOK xmlns=“”> <TITLE>All About XML</TITLE> <AUTHOR>Joe Developer</AUTHOR> <PUBLISHER xmlns=“urn:publishers:publinfo”> <NAME>Microsoft Press</NAME> </PUBLISHER> </BOOK>

43 Namespaces: Attributes
Unqualified attributes do NOT belong to any namespace Even if there is a default namespace This differs from elements, which belong to the default namespace

44 Entities Entities provide a mechanism for textual substitution, e.g.
You can define your own entities Parsed entities can contain text and markup Unparsed entities can contain any data JPEG photos, GIF files, movies, etc. Entity Substitution < & &

45 CDATA By default, all text inside an XML document is parsed
You can force text to be treated as unparsed character data by enclosing it in <![CDATA[ ]]> Any characters, even & and <, can occur inside a CDATA Whitespace inside a CDATA is (usually) preserved The only real restriction is that the character sequence ]]> cannot occur inside a CDATA CDATA is useful when your text has a lot of illegal characters (for example, if your XML document contains some HTML text)

46 Pure XML -- Instance Model
XML 1.0 Standard: no explicit data model only syntax of well-formed and valid (wrt. a DTD) documents implicit data model: nested containers ("boxes within boxes") labeled ordered trees (=a semistructured data model) relational, object-oriented, other data: easy to encode C: "bar" A: B: "foo" "lab" A <A> <B>foo</B> <C>bar</C> <C>lab</C> </A> B C C "foo" "bar" "lab" children are ordered

47 Example: Relational Data to XML
tuple A a1 /A B b1 /B C c1 /C /tuple A a2 /A B b2 /B C c2 /C /R c2 b2 a2 c3 b3 a3 c1 b1 a1 C B A R tuple A B C a1 b1 c1 a2 b2 c2 a3 b3 c3

48 Adding Structure and Semantics
XML Document Type Definitions (DTDs): define the structure of "allowed" documents (i.e., valid wrt. a DTD)  database schema => improve query formulation, execution, ... XML Schema defines structure and data types allows developers to build their own libraries of interchanged data types XML Namespaces identify your vocabulary

49 XML Related Technologies I
XHTML - Extensible HTML CSS - Cascading Style Sheets XSL - Extensible Style Sheet Language XSL consists of three parts: XML Document Transformation (renamed XSLT, see below), a pattern matching syntax (renamed XPath, see below), and a formatting object interpretation.  XSLT - XML Transformation XSLT is far more powerful than CSS. It can be used to transform XML files into many different output formats. XPath - XML Pattern Matching XPath is a language for addressing parts of an XML document. XPath was designed to be used by both XSLT and XPointer.

50 XML Related Technologies II
XLink - XML Linking Language The XML Linking Language (XLink), allows elements to be inserted into XML documents in order to create links between XML resources. XPointer - XML Pointer Language The XML Pointer Language (XPointer), supports addressing into the internal structures of XML documents, such as elements, attributes, and content. DTD - Document Type Definition A DTD can be used to define the legal building blocks of an XML document. Namespaces XML namespaces defines a method for defining element and attribute names used in XML by associating them with URI references.

51 XML Related Technologies III
DOM - Document Object Model The DOM defines interfaces, properties and methods to manipulate XML documents. XSD - XML Schema Schemas are powerful alternatives to DTDs. Schemas are written in XML, and support namespaces and data types. XQL - XML Query Language The XML Query Language supports query facilities to extract data from XML documents. SAX - Simple API for XML SAX is another interface to read and manipulate XML documents

52 References W3 Schools XML Tutorial W3C XML page XML Tutorials
W3C XML page XML Tutorials Online resource for markup language technologies

53 XML in .NET

54 Overview XML use is ubiquitous throughout .NET Web Services ASP.NET
Based on XML standards: SOAP, WSDL, UDDI, … ASP.NET Application information stored in XML-based configuration files ADO.NET Provides conversion between DataSets and XML DataSets are serialized as XML

55 Overview XML classes built on industry standards
e.g., DOM Level 2 Core, XML Schemas, SOAP Introduces a stream-based (“pull”) interface vs. the traditional SAX “push” model Natural evolution of MSXML 3.0 (4.0) MSXML 3.0 still available in .NET via COM Interop .NET XML classes are well-factored for functionality, performance and extensibility

56 XmlNode Represents a single node in a XML document hierarchy
An abstract class Properties and methods to traverse XML document hierarchy query properties modify nodes delete notes

57 XmlDocument Implements W3C XML Document Object Model (DOM) Level 1 and Level 2 specifications Implements XmlNode Represents an entire XML document All nodes are available to view/manipulate Cached in memory XmlDocument is analogous to a DataSet Events for changing, inserting and removing nodes

58 XmlLinkedNode Implements XmlNode
Retrieves the node immediately preceding or following the current node An abstract class from which XmlElement is derived Declaration: public abstract class XmlLinkedNode : XmlNode

59 XmlElement Represents an element in the DOM tree
Properties and methods to view, modify, and create element objects Declaration: Code example: public class XmlElement : XmlLinkedNode XmlDocument myXmlDoc = new XmlDocument(); myXmlDoc.Load (“c:\Sample.xml”); // DocumentElement retrieves the root element XmlElement root = myXmlDoc.DocumentElement;

60 XmlAttribute Implements XmlNode
Represents an attribute of an XmlElement Valid and/or default values defined by schema Declaration: public class XmlAttribute : XmlNode

61 XmlAttribute Code example: XmlDocument myXmlDoc = new XmlDocument();
myXmlDoc.Load (“c:\Sample.xml”); // Get the attribute collection of the root element XmlAttributeCollection attrColl = myXmlDoc.DocumentElement.Attributes; // Create a new attribute and set it’s value XmlAttribute newAttr = myXmlDoc.CreateAttribute(“value”); newAttr.Value = “new value”; // Append the new attribute to the collection attrColl.Append(newAttr);

62 XmlNode:IXPathNavigable
XmlNode has simple methods for traversing a XML document hierarchy XmlNode is an interface for accessing XML data using a cursor model Provides a generic navigation mechanism Support for XPath expressions through IXPathNavigable interface Can select and navigate a subset of a document Properties and methods to view, modify, copy, delete nodes

63 XPathNavigator Allows navigation over a XmlDocument
XmlDocument is derived from XmlNode, which implements IXPathNavigable Caveats “Current” node remains current when moved Can be in a null state when not pointing to a node Does not “walk” off end of tree Failed methods leave XPathNavigator where it was public class XmlDocument : XMLNode { XMLNode IXPathNavigable.CreateNavigator() { } }

64 XPathNavigator Declaration: Constructor: Code example:
public class XPathNavigator : IXPathNavigable public XPathNavigator (XmlDocument document); XmlDocument myXmlDoc; myXmlDoc.Load (“c:\Sample.xml”); XPathNavigator nav = myXmlDoc.CreateNavigator(); nav.MoveToRoot(); // move to root element nav.MoveToNext(); // move to next element

65 XPathNavigator Example: iterate over a subset of nodes
XmlDocument doc = new XmlDocument(); doc.Load("person.xml"); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iter = nav.Select("/person/name"); while (iter.MoveToNext ()) { // process selection here… with iter.Current.Value } Example: sum all Prices in a document public static void SumPriceNodes(XPathNavigator nav) { // in this case, evaluate returns a number Console.WriteLine("sum=" + nav.Evaluate("sum(//Price)")); }

66 XmlReader XmlReader is an abstract class that provides fast, non- cached, forward-only, read-only access to XML data Uses a “pull” model Simpler than the SAX “push” model User can easily implement “push” model if desired But the reverse is not true Reads in depth-first order Same order as textual XML data Analogous to an ADO.NET DataReader

67 XmlTextReader Forward-only, read-only, non-cached access to stream-based XML data Implements XmlReader Access to data by parsing text input from: Streams TextReader objects Strings Properties and methods to view elements and attributes Event support for validation

68 XmlNodeReader Forward-only, non-cached access to XML data
Implements XmlReader Access to data via XPathNavigator Reads data from an entire XmlDocument or a specific XmlNode Properties and methods to view elements and attributes

69 XmlWriter Abstract class providing fast, non-cached, forward- only, write-only creation of XML data Makes it easy to create well-formed XML data in a type-safe manner

70 XmlTextWriter Forward-only, non-cached method of writing XML data to a stream Implements XmlWriter Can write to: Streams Files TextWriter objects Properties and methods to write syntactically valid XML

71 Other XML Namespaces System.Xml – Core XML namespace
System.Xml.XPath – contains the XPathNavigator, XPath parser and evaluation engine System.Xml.Xsl – support XSLT transformations System.Xml.Serialization – Classes to serialize objects into XML documents or streams System.Xml.Schema – Supports XSD schemas

72 Relational Data and XML Relational Support in System.Xml
XmlDataDocument XPathDocument XPathNavigator Build a relation on a DataSet Built-in XML support in SQL Server 2000

73 Relational Data and XML XmlDataDocument
Extends XmlDocument to include support for relational data (files, RDBMS, etc.) Provides a DataSet property, which is kept synchronized with the XML data Schema support Schema can be loaded/saved as XSD Schema can be inferred from XML data Loading the XmlDataDocument and the DataSet synchronize them together The DataSet can be populated from either an XmlReader or a managed data provider Adding a row to the XmlDataDocument updates the DataSet Adding a row to the DataSet, however, will update the XmlDataDocument only if the node is mapped to a DataSet table The XmlDataDocument is a view into relational data – allowing full support of the DOM for viewing/updating

74 Relational Data and XML XmlDataDocument
XSL/T, X-Path, Validation, etc. Controls, Designers, Code-gen, etc. XmlData- Document DataSet Sync XmlReader XmlText- Reader XmlNode- DataAdapter SqlData- Adapter OleDbData- DataReader SqlData- Reader OleDbData-

75 Relational Data and XML XmlDataDocument
XmlDataDocument dataDoc = new XmlDataDocument(); // Read the XML into a DataSet dataDoc.DataSet.ReadXml(new StreamReader(“c:\example.xml”); foreach(DataTable table in dataDoc.DataSet.Tables) { foreach(DataColumn column in table.Columns) { } foreach(DataRow row in table.Rows) { foreach(Object value in row.ItemArray) { } }

76 Relational Data and XML DataDocumentNavigator
Implements XmlNavigator over an XmlDataDocument Contains the features of DocumentNavigator Cursor model access XPath support, etc. Includes support for relational data (XmlDataDocument)

77 Relational Data and XML Building a DataSet Relation
Create DataSet Define tables: DataSet dataset = new DataSet(); dataset.Name = "BookAuthors"; DataTable authors = new DataTable("Author"); DataTable books = new DataTable("Book");

78 Relational Data and XML Building a DataSet Relation
Define columns Define keys: DataColumn id = authors.Columns.Add("ID", typeof(Int32)); id.AutoIncrement = true; authors.PrimaryKey = new DataColumn[] {id}; DataColumn name = new authors.Columns.Add("Name", typeof(String)); DataColumn isbn = books.Columns.Add("ISBN", typeof(String)); books.PrimaryKey = new DataColumn[] {isbn}; DataColumn title = books.Columns.Add("Title", typeof(String)); DataColumn authid = books.Columns.Add(“AuthID”, typeof(Int32)); DataColumn[] foreignkey = new DataColumn[] {authid};

79 Relational Data and XML Building a DataSet Relation
Add the tables to the DataSet: dataset.Tables.Add (authors); dataset.Tables.Add (books);

80 Relational Data and XML Building a DataSet Relation
Add data and save the DataSet: DataRow shkspr = authors.NewRow(); shkspr["Name"] = "William Shakespeare"; authors.Rows.Add(shkspr); DataRelation bookauth = new DataRelation("BookAuthors", authors.PrimaryKey, foreignkey); dataset.Relations.Add (bookauth); DataRow row = books.NewRow(); row["AuthID"] = shkspr["ID"]; row["ISBN"] = "1000-XYZ"; row["Title"] = "MacBeth"; books.Rows.Add(row); dataset.AcceptChanges();

81 Relational Data and XML XML Support in SQL Server 2000
Ability to query SQL Server over HTTP Retrieve XML using SELECT … FOR XML Retrieve XML using XPath queries Write XML data using OPENXML rowset provider

82 Resources
Microsoft Press Books ( XML Step By Step XML In Action Developing XML Solutions O’Reilly Press XML In A Nutshell

83 Resources XML in .NET ml/xml.asp Working with XML in the .NET Platform 01/05may01/dw0102/dw0102.asp

Download ppt "ICS 434 Advanced Database Systems"

Similar presentations

Ads by Google