DevCon 2000 Adam Cogan eXtensible Markup Language (XML)
-
Upload
tabitha-freeman -
Category
Documents
-
view
220 -
download
1
Transcript of DevCon 2000 Adam Cogan eXtensible Markup Language (XML)
DevCon 2000DevCon 2000
Adam CoganAdam Cogan
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
DevCon 2000DevCon 2000
About AdamAbout 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: [email protected]
DevCon 2000DevCon 2000
… Agenda… 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
DevCon 2000DevCon 2000
… What is the Problem?… 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.
DevCon 2000DevCon 2000
What is an Example?…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.
DevCon 2000DevCon 2000
The Solution - XML …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.
DevCon 2000DevCon 2000
… Fundamentals… 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>
DevCon 2000DevCon 2000
… XML vs HTML
HTML is all about display! XML is all about data! HTML can contain XML - and vice versa
DevCon 2000DevCon 2000
… 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?
DevCon 2000DevCon 2000
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
DevCon 2000DevCon 2000
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>
DevCon 2000DevCon 2000
… XML and Data
XML can represent regular, relational record-style data
It can also represent hierarchical data It can, of course, represent irregular data
too
DevCon 2000DevCon 2000
… 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>
DevCon 2000DevCon 2000
… 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
DevCon 2000DevCon 2000
… 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 #
DevCon 2000DevCon 2000
… XML Components
Content
Traditional WYSIWYG
Document
Presentation
No RealStructure
XML Document
ContentXML
PresentationXSL
StructureXML
DevCon 2000DevCon 2000
XML - Six Things to Know …
Start and End Tags Entity References Attribute Assignments Comments Processing Instructions Document Type Declarations (Schema-
Future)
DevCon 2000DevCon 2000
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>
DevCon 2000DevCon 2000
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>
DevCon 2000DevCon 2000
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
DevCon 2000DevCon 2000
… Comments
XML comments use the exact same form as HTML comments: <!– My Comment -->
DevCon 2000DevCon 2000
… 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
DevCon 2000DevCon 2000
… Document Type Declaration
Allows you to instruct the parser, where to find the DTD:
<!DOCTYPE type LOCATION “path”> <!DOCTYPE HTML PUBLIC
“//goose/example.dtd”>
DevCon 2000DevCon 2000
… Create Your Own XML… Create Your Own XML
Creating XML file manually Create XML file with ADO 2.5
DevCon 2000DevCon 2000
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.
DevCon 2000DevCon 2000
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
DevCon 2000DevCon 2000
XML Validation-XML Applications …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)
DevCon 2000DevCon 2000
name
lastfirst
Jane Doe
orders
order orderdate
1998-07-16
date
1998-07-23
Commentcustomer list
root
IDcustomer
345
IDcustomer
120
Document
… Parsing XML into Nodes… Parsing XML into Nodes
DevCon 2000DevCon 2000
Document Object Model (DOM) …Document Object Model (DOM) …
ID
baz456
ID
bar123
mydocument
345
root
root = mydocument.documentElement;
root
Customer Customer
Document
DevCon 2000DevCon 2000
345
Document Object Model (DOM) …Document Object Model (DOM) …
ID
baz456
ID
bar123
nodemydocument
root = mydocument.documentElement; node = root.childNodes.item(1);
root root
Customer Customer
Document
DevCon 2000DevCon 2000
8910
Document Object Model (DOM) …Document Object Model (DOM) …
IDCustomer
baz456
IDCustomer
bar
root
123
node
update
mydocument
root = mydocument.documentElement; node = root.childNodes.item(1); node.childNodes.item(0).nodeValue =
“8910”;
root
Document
DevCon 2000DevCon 2000
8910
Document Object Model (DOM) …Document Object Model (DOM) …
IDCustomer
baz456
IDCustomer
bar
root
123
node
update
mydocument
attr
root = mydocument.documentElement; node = root.childNodes.item(1); node.childNodes.item(0).nodeValue =
“8910”; attr = node.attributes.getNamedItem(“ID”);
root
Document
DevCon 2000DevCon 2000
newNode
8910
root = mydocument.documentElement; node = root.childNodes.item(1); node.childNodes.item(0).nodeValue = “8910”; attr = node.attributes.getNamedItem(“ID”); root.insertBefore(newNode,root.firstChild);
Document Object Model (DOM) …Document Object Model (DOM) …
IDCustomer
baz456
IDCustomer
bar
root
123
node
update
mydocument
attrroot
Document
DevCon 2000DevCon 2000
newNode
Document Object Model (DOM) …Document Object Model (DOM) …
456
IDCustomer
bar
root
123
mydocument
root
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);
Document
DevCon 2000DevCon 2000
… Working With XML Files and Recordsets
… 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
DevCon 2000DevCon 2000
… Using XML - XSL… Using XML - XSL
XSL – Extensible Style Language provides the formatting and presentation.
Can filter, sort and layout XML. Apply filters and sorts dynamically.
DevCon 2000DevCon 2000
Demo-XML and ASP and ADODemo-XML and ASP and ADO
Build XML using vb script or Java script
Update data using XML DOM
DevCon 2000DevCon 2000
Summary: XML why is it so cool?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
DevCon 2000DevCon 2000
XML Suggested ReadingsXML 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