440 likes | 617 Views
eXtensible Markup Language (XML). Adam Cogan. About Adam. Developer - experience with: internal corporate development and generic off-the-shelf databases Clients: Tennis Australia, Cabletron, Cisco…. President - Access /ASP/SQL Server User Group, Sydney Speaker for Microsoft Roadshows
E N D
eXtensible Markup Language (XML) Adam Cogan
About Adam • Developer - experience with: • internal corporate development and • generic off-the-shelf databases • Clients: Tennis Australia, Cabletron, Cisco…. • President - Access/ASP/SQL Server User Group, Sydney • Speaker for Microsoft Roadshows • Email: adamcogan@ssw.com.au
… Agenda • Why do we need XML? • XML Overview • XML Structure • Validation • Using XML • Data binding for the web • XSL • VBA Applications (Using Document Object Model) • XML for n-tier
… What is the Problem? • Applications cannot understand other applications data. • Laying out data on documents, web pages and forms has to be custom. • There is no universal standard for data structure.
What is an Example?… • Let's say you receive an email and wish to save the contact information of the sender. Generally, you would copy the text about the sender and paste it in an application. • To use the contact information in Outlook, you would paste each part of the contact data into the appropriate field. • To use the contact in Word you would past the text in Word. • To do a bar graph showing what city your contacts reside in the data would be moved to Excel.
The Solution - XML … • With XML, all of these application could understand and use the data easily. • XML makes it easy for different people using different kind of software to understand and exchange information.
… Fundamentals • XML is not an application. • A browser simply reads a text stream and displays it in the browser. • HTML will format the text that is shown in the document (e.g. make the text bold). • <B> Adam </B> • XML describes the data in a document or web page. • <FirstName> Adam </FirstName>
… XML vs HTML • HTML is all about display! • XML is all about data! • HTML can contain XML - and vice versa
… XML – The Standard • XML is a W3C standards-based text format for interchange of data • http://www.w3.org/TR/REC-xml • Why wasn’t ASCII and CSV good enough?
Simple Date Example … • XML defines data, not display. • HTML defines the formatting of text. • HTML can make text appear bold: • <B>May 10, 2000</B> • HTML defining some text - but giving no meaning to it • <OrderDate Format = “long”>May 10, 2000 </OrderDate> • XML defining a date, but not saying how it should be displayed • Elements – Attributes - DTD
Business Card Example … <BusinessCard> <Name> <FirstName>Adam</FirstName> <LastName>Cogan</LastName> </Name> <Address> <Address>101 SW Fifth</Address> <City>Neutral Bay, NSW, 2087</City> </Address> <Phone> <Home>9953 3000</Home> <Mobile>04 1985 1995</Mobile> </Phone> </BusinessCard>
… XML andData • XML can represent regular, relational record-style data • It can also represent hierarchical data • It can, of course, represent irregular data too
… Invoice Example <Invoice> <From>C. Brooks. </From> <To>C. McCall </To> <Date>2/1/99 </Date> <Amount>$189.00 </Amount> <Tax>10% </Tax> <Total>$207.90</Total> </Invoice>
… Making It Work • XML File – for the data • XSL File – Style sheet for the XML • Add the "Processing Instruction" at the top of the XML file • In-Line XML
… A Typical Document • What does every document consist of? • Data - the words or content of the document. • Presentation - the way information is presented to the user of the document. Fonts, style, color. • Structure - consists of type and elements. • Type - Memo, Invoice, PO, License, etc. • Elements - Name, Amount, License #
Traditional WYSIWYG Document XML Document Presentation XSL Presentation Content Content XML Structure XML No Real Structure … XML Components
XML - Six Things to Know … • Start and End Tags • Entity References • Attribute Assignments • Comments • Processing Instructions • Document Type Declarations (Schema-Future)
Start and End Tags … • Must be a matched set – Opening and closing tags required: <greeting></greeting> • No spaces allowed : <PC Brand> • Can’t begin with a number: <3Topic> • No spaces in end tag: </ greeting>
Entity References (Your Data!) … • An entity is a unit of text that can be inserted into the XML document. • XML entities can reference a single character or an entire novel of data. • There are two types of entities - default and defined. • <BirthDate> • 20/2/1973 • </BirthDate> • <BirthDate> • 20/2/1973 • </BirthDate>
Attribute Assignment … • Allows you to describe the type of data your are dealing with. • [name of attribute] “=“ [value] • <greeting language=“French”> • Must be in quotes. • Multiple attributes are supported. • This works exactly the same as in HTML
… Comments • XML comments use the exact same form as HTML comments: <!– My Comment -->
… Processing Instructions • Allows XML to store application specific information. • Must be in the declaration section of the document. • Three main types: • <?xml version = “1.0”?> • DTD • Style Sheet
… Document Type Declaration • Allows you to instruct the parser, where to find the DTD: • <!DOCTYPE type LOCATION “path”> • <!DOCTYPE HTML PUBLIC “//goose/example.dtd”>
… Create Your Own XML • Creating XML file manually • Create XML file with ADO 2.5
XML Data-Schemas • The Microsoft ADO implementation. • A way to describe the structure, content and data type of XML-data. • Extends the functionality of DTD's. • Uses an XML Grammer. • Can be used to validate XML. • Currently Microsoft only technology.
XML Validation-DTD … • XML - Works with DTD, “Document Type Definition”, and the data to provide and define “structure”. • XML ‘Applications’ • Industry Standards have begun to develop. • Allows an industry to choose a standard format for data exchange
XML Validation-XML Applications … • Industry members agreeing on a set of tags for Validation • RealML (Real Estate) • BizTalk • OFX (Open Financial Exchange Format) • Download Technology • MathML • ChemML • CDF (Channel Definition Format)
… XML Validation XML Doc. XML Parser XML Client XML DTD
… Parsing XML into Nodes Document root Comment customer list customer customer ID ID 345 120 name orders first last order order date date Jane Doe 1998-07-16 1998-07-23
Document Object Model (DOM) … mydocument Document root root Customer Customer ID ID bar baz 123 456 345 • root = mydocument.documentElement;
Document Object Model (DOM) … mydocument Document node root root Customer Customer ID ID bar baz 123 456 345 • root = mydocument.documentElement; • node = root.childNodes.item(1);
Document Object Model (DOM) … mydocument Document node root root Customer Customer ID ID bar baz 123 456 8910 update • root = mydocument.documentElement; • node = root.childNodes.item(1); • node.childNodes.item(0).nodeValue = “8910”;
Document Object Model (DOM) … mydocument Document node root root attr Customer Customer ID ID bar baz 123 456 8910 update • root = mydocument.documentElement; • node = root.childNodes.item(1); • node.childNodes.item(0).nodeValue = “8910”; • attr = node.attributes.getNamedItem(“ID”);
newNode Document Object Model (DOM) … mydocument Document node root root attr Customer Customer ID ID bar baz 123 456 8910 update • root = mydocument.documentElement; • node = root.childNodes.item(1); • node.childNodes.item(0).nodeValue = “8910”; • attr = node.attributes.getNamedItem(“ID”); • root.insertBefore(newNode,root.firstChild);
newNode Document Object Model (DOM) … mydocument Document root root Customer ID bar 123 456 • root = mydocument.documentElement; • node = root.childNodes.item(1); • node.childNodes.item(0).nodeValue = “8910”; • attr = node.attributes.getNamedItem(“ID”); • root.insertBefore(newNode,root.firstChild); • root.removeNode(root.lastChild);
… Working With XML Files and Recordsets • Data from a database saved as XML • Retrieve XML data and display in grid • Retrieve XML data and save to a database
… XML Data Binding • Using Data Binding with IE 5.
… Using XML - XSL • XSL – Extensible Style Language provides the formatting and presentation. • Can filter, sort and layout XML. • Apply filters and sorts dynamically.
Demo-XML and ASP and ADO • Build XML using vb script or Java script • Update data using XML DOM
Summary: XML why is it so cool? • EASY and Powerful! • Standard way to represent data • Abstraction and Ubiquity with Robustness • End-to-end (standard) data protocol • Standard data protocol from Tier 3 to Tier 2 • Standard data protocol from Tier 2 to Tier 1 • Express data in format that only requires HTTP (See ‘XML for n-Tier’ session coming up) • Rich Object Model (DOM) in Windows, Java • Cross Platform: Parsers for every OS around • Including Windows, Linux, Unix, Mac, CE, PalmOS
XML Suggested Readings • Chapter 27 - Access 2000 Development Unleashed (SAMS Publishing) • MSDN • XML Programming With VB and ASP (Manning Publishing) • XML IE5 Programmers Reference (WROX Press) • Examples at www.ssw.com.au