ICS 434 Advanced Database Systems

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Transforming XML XMLNamespaces, XSLT. XML Namespaces Sometimes it is necessary to mix XML elements –Different types of content –Use of markup to convey.
What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML: Extensible Markup Language
XML & Data Structures for the Internet Yingcai Xiao.
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
An Introduction to XML Based on the W3C XML Recommendations.
XML 6.2 XSL / XSLT 6. What is XSL? XSL stands for eXtensible Stylesheet Language CSS was designed for styling HTML pages, and can be used to style XML.
6 XML 6.1 XML.
Sistemi basati su conoscenza XML Prof. M.T. PAZIENZA a.a
XML A brief introduction ---by Yongzhu Li. XML --- a brief introduction 2 CSI668 Topics in System Architecture SUNY Albany Computer Science Department.
26-Jun-15 XML. 2 HTML and XML, I XML stands for eXtensible Markup Language HTML is used to mark up text so it can be displayed to users XML is used to.
DECO 3002 Advanced Technology Integrated Design Computing Studio Tutorial 5 – XML Basic School of Architecture, Design Science and Planning Faculty of.
Sistemi basati su conoscenza XML Prof. M.T. PAZIENZA a.a
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Tutorial 11 Creating XML Document
Introduction to XML: Yong Choi CSU Bakersfield.
XML Introduction By Hongming Yu Feb 6 th, Index Markup Language: SGML, HTML, XML An XML example Why is XML important XML introduction XML applications.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Introduction to XML This material is based heavily on the tutorial by the same name at
Introduce of XML Xiaoling Song CS157A. What is XML? XML stands for EXtensible Markup Language XML stands for EXtensible Markup Language XML is a markup.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
XML Fundementals XML vs.. HTML XML vs.. HTML XML Document (elements vs. attributes) XML Document (elements vs. attributes) XML and RDBMS XML and RDBMS.
XML – Extensible Markup Language Sivakumar Kuttuva & Janusz Zalewski.
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Tutorial 1: XML Creating an XML Document. 2 Introducing XML XML stands for Extensible Markup Language. A markup language specifies the structure and content.
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
1 Dr Alexiei Dingli XML Technologies XML Advanced.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML.
1 Dr Alexiei Dingli XML Technologies XML. 2 XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry.
Waqas Anwar Next SlidePrevious Slide. Waqas Anwar Next SlidePrevious Slide XML XML stands for EXtensible Markup Language.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
What it is and how it works
XML Introduction. Markup Language A markup language must specify What markup is allowed What markup is required How markup is to be distinguished from.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
IS446: Internet Software Development Dr. Azeddine Chikh.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Web Technologies Lecture 4 XML and XHTML. XML Extensible Markup Language Set of rules for encoding a document in a format readable – By humans, and –
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
Martin Kruliš by Martin Kruliš (v1.1)1.
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Introduction to XML Extensible Markup Language.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
DHTML.
Unit 4 Representing Web Data: XML
XML QUESTIONS AND ANSWERS
XML in Web Technologies
Chapter 7 Representing Web Data: XML
XML Introduction By Hongming Yu Feb 6th, 2002.
What is XML?.
Presentation transcript:

ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals Information & Computer Science Department

Introduction to XML

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

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

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 http://www.w3.org/TR/REC-xml Oct 2002 XML 1.1 Candidate Recommendation updates XML to use Unicode 3

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

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

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

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

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=‘1-861003-11-0’> <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>

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

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

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

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

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

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

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

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

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

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

An XML Document <?xml version='1.0'?> <bookstore> <book genre=‘autobiography’ publicationdate=‘1981’ ISBN=‘1-861003-11-0’> <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=‘0-201-63361-2’> <title>The Confidence Man</title> <first-name>Herman</first-name> <last-name>Melville</last-name> <price>11.99</price> </bookstore>

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>

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

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

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

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

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?

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

Example: the xml file <?xml version="1.0" encoding="ISO-8859-1"?> <?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>

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; }

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

Example: the xml file <?xml version="1.0" encoding="ISO-8859-1"?> <?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>

Example: the xsl file <?xml version="1.0" encoding="ISO-8859-1"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"> <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>

View the result in IE 6

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>

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")

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

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.

Namespaces: Declaration Namespace declaration examples: xmlns: bk = “http://www.example.com/bookinfo/” xmlns: bk = “urn:mybookstuff.org:bookinfo” xmlns: bk = “http://www.example.com/bookinfo/” Namespace declaration Prefix URI (URL)

Namespaces: Examples <BOOK xmlns:bk=“http://www.bookstuff.org/bookinfo”> <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=“http://www.bookstuff.org/bookinfo” 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>

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=“http://www.bookstuff.org/bookinfo”> <TITLE>All About XML</TITLE> <AUTHOR>Joe Developer</AUTHOR>

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=“www.bookstuff.org/bookinfo”> <TITLE>All About XML</TITLE> <AUTHOR>Joe Developer</AUTHOR> <PUBLISHER xmlns=“urn:publishers:publinfo”> <NAME>Microsoft Press</NAME> </PUBLISHER> </BOOK>

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

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

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)

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

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

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

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.

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.

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

References W3 Schools XML Tutorial W3C XML page XML Tutorials http://www.w3schools.com/xml/default.asp W3C XML page http://www.w3.org/XML/ XML Tutorials http://www.programmingtutorials.com/xml.aspx Online resource for markup language technologies http://xml.coverpages.org/

XML in .NET

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

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

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

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

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

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;

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

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);

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

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() { } }

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

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)")); }

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

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

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

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

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

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

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

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

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-

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) { } }

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)

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");

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};

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

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();

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

Resources http://msdn.microsoft.com/xml/ http://www.xml.com/ http://www.w3.org/xml/ Microsoft Press Books (http://mspress.microsoft.com/) XML Step By Step XML In Action Developing XML Solutions O’Reilly Press XML In A Nutshell

Resources XML in .NET http://msdn.microsoft.com/msdnmag/issues/01/01/x ml/xml.asp Working with XML in the .NET Platform http://www.xmlmag.com/upload/free/features/xml/20 01/05may01/dw0102/dw0102.asp