Comp2513Comp2513
XML – eXtensible Markup XML – eXtensible Markup LanguageLanguage
Daniel L. Silver, Ph.D.Daniel L. Silver, Ph.D.
2002 Daniel L. Silver 2
ObjectivesObjectives
To discuss problems with the HTML based To discuss problems with the HTML based web and introduce XML (and related web and introduce XML (and related methods) as the next generation markup methods) as the next generation markup language language
References: DDEA Ch. 8, Sharma Ch.7 and References: DDEA Ch. 8, Sharma Ch.7 and External Web LinksExternal Web Links
2002 Daniel L. Silver 3
OutlineOutline
Problems with the HTML based WebProblems with the HTML based Web The XML ideaThe XML idea XML fundamentalsXML fundamentals XML useXML use
2002 Daniel L. Silver 4
Problems with Problems with the HTML based Webthe HTML based Web
HTML documents focus on display and not HTML documents focus on display and not structure and meaning of data - an information structure and meaning of data - an information maze devoid of meaningmaze devoid of meaning
Inefficient use of tags (every instance of data must Inefficient use of tags (every instance of data must be tagged)be tagged)
Fixed number of tags - can not be extended (not Fixed number of tags - can not be extended (not extensible)extensible)
HTML search is based on keywords without HTML search is based on keywords without contextcontext
Client-server applications cannot easily exchange Client-server applications cannot easily exchange data using HTMLdata using HTML
2002 Daniel L. Silver 5
HTML focuses on display syntaxHTML focuses on display syntax
HTML tags such as <B>Simpson<\B> tell HTML tags such as <B>Simpson<\B> tell how to display the word “Simpson”how to display the word “Simpson”
Focus is on presentation (format, syntax)Focus is on presentation (format, syntax) But its does not define what But its does not define what “Simpson”“Simpson” means means
– A persons name? A city? A company?A persons name? A city? A company? Or its structural relationship to other dataOr its structural relationship to other data
– Full name? Last name? First name?Full name? Last name? First name?
2002 Daniel L. Silver 6
The XML ideaThe XML idea
eXtensible Markup LanguageeXtensible Markup Language XML defines meaning (semantics): XML defines meaning (semantics):
<lname>Simpson<\lname><lname>Simpson<\lname> In terms of structural relationships …In terms of structural relationships … Independent of Independent of
presentationpresentation<mail_adrs> <fname>Homer<\fname> <lname>Simpson<\lname> <strnum>1234<\strnum> <str>Hickup Lane<\str><\mail_adrs>
2002 Daniel L. Silver 7
What is XML?What is XML?
1996 - A simplified form of SGML for the web 1996 - A simplified form of SGML for the web (Standardized General Markup Language) (Standardized General Markup Language)
Both machine and human readableBoth machine and human readable Separates content, structure Separates content, structure
and presentationand presentation Extensible (users can define structure and Extensible (users can define structure and
meaning)meaning) Supports information reuse and processing Supports information reuse and processing
autonomy (application decides how to use/present)autonomy (application decides how to use/present)
SGML
HTMLXML
2002 Daniel L. Silver 8
The W3C’s Basic Requirements for The W3C’s Basic Requirements for XMLXML
XML shall be straightforwardly usable over the Internet.XML shall be straightforwardly usable over the Internet. XML shall support a wide variety of applications.XML shall support a wide variety of applications. XML shall be compatible with SGML.XML shall be compatible with SGML. It shall be easy to write programs which process XML It shall be easy to write programs which process XML
documents.documents. The number of optional features in XML is to be kept to The number of optional features in XML is to be kept to
the absolute minimum, ideally zero.the absolute minimum, ideally zero. XML documents should be human-legible and XML documents should be human-legible and
reasonably clear.reasonably clear. XML documents should be easy to prepare.XML documents should be easy to prepare. The design of XML shall be formal and concise.The design of XML shall be formal and concise. Terseness in XML markup is of minimal importance.Terseness in XML markup is of minimal importance.
2002 Daniel L. Silver 9
XML FundamentalsXML Fundamentals<?xml version = "1.0"?>…<contacts> <contact> <LastName>Black</LastName> <FirstName>John</FirstName> </contact> …</contacts>
XML Content
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl = "http://www.w3.org/TR/WD-xsl">…
<!ELEMENT contacts (contact)* ><!ELEMENT contact (LastName, FirstName) ><!ELEMENT LastName (#PCDATA) ><!ELEMENT FirstName (#PCDATA) >
Presentationin Context
XSL Presentation
DTD Structure
2002 Daniel L. Silver 10
XML’s Intended UseXML’s Intended Use
Standard format for exchanging dataStandard format for exchanging data Promote cross-platform and cross-application Promote cross-platform and cross-application
schema – independent of data content, use and schema – independent of data content, use and presentationpresentation
Oriented toward giving meaning to data, and does Oriented toward giving meaning to data, and does not emphasize display issuesnot emphasize display issues
Client – describes valid data for displayClient – describes valid data for display Server – describes valid data for exchangeServer – describes valid data for exchange
2002 Daniel L. Silver 11
XMLs Intended UseXMLs Intended Use
Allows organizations to maintain proprietary Allows organizations to maintain proprietary databases while at the same time communicate databases while at the same time communicate information with one anotherinformation with one another
Schemas for specific domains have been created:Schemas for specific domains have been created:– MusicMusic
– Chemical symbols Chemical symbols
– Mathematical formulasMathematical formulas
– Common industry models (EDI for B2B)Common industry models (EDI for B2B)
– Web resource descriptions (directories, addresses)Web resource descriptions (directories, addresses)
2002 Daniel L. Silver 12
XML versus HTMLXML versus HTML
XML is not a replacement for HTMLXML is not a replacement for HTML XML and HTML were designed with XML and HTML were designed with
different goals:different goals:– HTML was designed to display data and to HTML was designed to display data and to
focus on how data looksfocus on how data looks– XML was designed to describe data and to XML was designed to describe data and to
focus on what data meansfocus on what data means They complement each otherThey complement each other
2002 Daniel L. Silver 13
XML eXtensibilityXML eXtensibility
XML allows you to create your own XML allows you to create your own definitions of data and there relationship to definitions of data and there relationship to other pieces of dataother pieces of data
Thus the nameThus the name
eXtensibleeXtensible ** Note that XML is ** Note that XML is
case sensitive **case sensitive **
<?xml version="1.0"?> <People> <Person> <Name> <First>Patrick</First> <Last>Joe</Last> </Name> </Person></People>
2002 Daniel L. Silver 14
Using IE to Explore XMLUsing IE to Explore XML
You can use Internet Explorer to view an You can use Internet Explorer to view an XML document directlyXML document directly
A plus (+) or minus sign (-) to the left of the A plus (+) or minus sign (-) to the left of the XML elements can be clicked to expand or XML elements can be clicked to expand or collapse the element structurecollapse the element structure
Or view the raw XML source using "View Or view the raw XML source using "View Source" from the browser menuSource" from the browser menu
Example: Example: cd_catalog.xmlcd_catalog.xml
2002 Daniel L. Silver 15
Defining XML StructureDefining XML Structure
DTD – DTD – Document Type DefinitionDocument Type Definition defines defines the fields in an XML document and their the fields in an XML document and their relation to one another (schema)relation to one another (schema)
Meta-data : data about dataMeta-data : data about data Can be included in .xml fileCan be included in .xml file or or
referenced as a .dtd filereferenced as a .dtd file Used by applications to Used by applications to
validate XML data validate XML data
<!ELMENT People (Person)* ><!ELMENT Person (Name) ><!ELMENT Name (First, Last) ><!ELMENT First (#PCDATA) ><!ELMENT Last (#PCDATA) >
2002 Daniel L. Silver 16
Processing an XML DocumentProcessing an XML Document<?xml version="1.0"?> <People> <Person> <Name> <First>Patrick</First> <Last>Joe</Last> </Name> </Person></People>
<!ELMENT People (Person)* ><!ELMENT Person (Name) ><!ELMENT Name (First, Last) ><!ELMENT First (#PCDATA) ><!ELMENT Last (#PCDATA) >
DTD Structure
XML Content An application that wishes to use XMLdata should parse the data using a DTD.There are two approaches:•DOM – read the entire document using the DTD and build a tree of elements•SAX – parse on demand (interactively) as each new element is encountered
DOM = Document Object ModelSAX = Simple API for XML
2002 Daniel L. Silver 17
Processing an XML DocumentProcessing an XML Document
Internet Explorer 5.0 (+) has a built in Internet Explorer 5.0 (+) has a built in DOM-based XML parser, DOM-based XML parser, msxml msxml
DTD can be embedded in XML or DTD can be embedded in XML or referencedreferenced
Examples:Examples:– simple_example.xmlsimple_example.xml with DTD embedded with DTD embedded– letter.xml letter.xml and and letter.dtdletter.dtd
2002 Daniel L. Silver 18
Displaying XML DocumentsDisplaying XML Documents
Can be accomplished in various ways, any Can be accomplished in various ways, any program that can parse the XML can program that can parse the XML can display the informationdisplay the information
Here is a simple HTML solution …Here is a simple HTML solution …– simple_contact.htmlsimple_contact.html - XML is embedded, DTD - XML is embedded, DTD
is not requiredis not required Javascript could be used insteadJavascript could be used instead
– article.xmlarticle.xml and and DOMexample.htmlDOMexample.html– note.xml note.xml and and note.htmlnote.html
2002 Daniel L. Silver 19
Displaying XML DocumentsDisplaying XML Documents
An XSL – eXtensible Stylesheet Layout can An XSL – eXtensible Stylesheet Layout can be usedbe used
Examples:Examples:Basic - Basic - contact3.xml using contact_list3.xslcontact3.xml using contact_list3.xsl
Full function – Full function – contact.xmlcontact.xml using contact_list.xsl using contact_list.xsl
Handheld – Handheld – contact2.xml using contact_list2.xslcontact2.xml using contact_list2.xsl
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl = "http://www.w3.org/TR/WD-xsl">…
2002 Daniel L. Silver 20
Transferring Data with XMLTransferring Data with XML
It is possible to use XML as a method of It is possible to use XML as a method of transferring meaningful data between transferring meaningful data between applications even when application applications even when application databases do not matchdatabases do not match
Adherence to XML DTD is the keyAdherence to XML DTD is the key
App A App BDB2 Oracle
JDBC ODBCXML
Common DTD
2002 Daniel L. Silver 21
Smart Searches on the InternetSmart Searches on the Internet
With XML and DTDs, keyword searches on With XML and DTDs, keyword searches on the Internet can now be aimed at the the Internet can now be aimed at the appropriate systems, databases, pagesappropriate systems, databases, pages
A syntactic search using IE: A syntactic search using IE: ““cook New York kitchen restaurant”cook New York kitchen restaurant”
… … would become …would become … A semantic search: A semantic search:
<occupation>cook</occupation><occupation>cook</occupation><city>New York</city><city>New York</city>
2002 Daniel L. Silver 22
VXMLVXML
Voice XMLVoice XML Sound embedded as content and processed Sound embedded as content and processed
as per style sheetas per style sheet Other media types will be used as well Other media types will be used as well
2002 Daniel L. Silver 23
eadmin and XMLeadmin and XML
EadminEadmin load.jsp?id=91load.jsp?id=91 servlet/LoadStoreservlet/LoadStore StoreLoader(store,xmlfile)StoreLoader(store,xmlfile)
store.xml store.dtd
2002 Daniel L. Silver 24
ReferencesReferences
http://www.w3.org/XML/http://www.w3.org/XML/ http://www.xmlfiles.com/xml/http://www.xmlfiles.com/xml/
2002 Daniel L. Silver 26
XMLXML
eXtensible Markup LanguageeXtensible Markup Language HTML tags such as <B>Silver<\B> tell HTML tags such as <B>Silver<\B> tell
how to display the word “Silver”how to display the word “Silver” But its does not define what it meansBut its does not define what it means XML defines meaning: XML defines meaning:
<last_name>Silver<\last_name><last_name>Silver<\last_name> And to create structure …And to create structure …