we will cover …
DESCRIPTION
We will cover …. What is XML? Components of an XML Document Document Type Definition (DTD) XML Data Islands Parsing XML and DOM XML presentation with CSS, XSL and XSLT XPath, XML and Database Integration Why use XML? Creating your own XML vocabulary Review of XML Applications and Tools - PowerPoint PPT PresentationTRANSCRIPT
(c) Nizar Mabroukeh 2001 1
We will cover… What is XML? Components of an XML Document Document Type Definition (DTD) XML Data Islands Parsing XML and DOM XML presentation with CSS, XSL and XSLT XPath, XML and Database Integration Why use XML? Creating your own XML vocabulary Review of XML Applications and Tools XML Resources
What is XML?
(c) Nizar Mabroukeh 2001 3
Markup Languages SGML:
Standard Generalized Markup Language Mother of Markup Languages
HTML Most popular presentation language for web
XML: Draws heavily on the merits & shortcomings of
HTML & SGML
(c) Nizar Mabroukeh 2001 4
Issues with HTMLMerits:
Very easy to use & learn Presentation technology It is the most popular
Shortcomings: NOT a data technology Poor Searching There is no Intelligence of content/data We loose meaning association with content Data cannot be represented hierarchically Limited set of tags
(c) Nizar Mabroukeh 2001 5
How does XML look? Simple XML data would look like
<book>
<title> XML Tech </title>
<author> YAG </author>
<level> Freshman </level>
</book>
<book> : Called the root node
(c) Nizar Mabroukeh 2001 6
XML HTML
Similar in appearance Both are based on SGML
BUT… XML describes data HTML displays data
XML
(eXtensible Markup Language)
(c) Nizar Mabroukeh 2001 8
What Is XML? “XML is a
platform-independent, self-describing, expandable, standard data exchange format that can be used either independently
or embedded and used within other
solutions.”
(c) Nizar Mabroukeh 2001 9
Platform Independent Windows Unix Macintosh Mainframe
(c) Nizar Mabroukeh 2001 10
Self-Describing Example:
<DATE>July 26, 1998</DATE>
Describes the information, not the presentation. Format flexible.
(c) Nizar Mabroukeh 2001 11
Expandable = Extensible HTML has a fixed set of tags
<H1>, <B>, <PRE>
XML lets you have your own tags <dangerous-substance>,
<Shakespearean-character>, <cash-equivalent>
(c) Nizar Mabroukeh 2001 12
Standard W3C (World Wide Web Consortium)
www.w3c.org
XML 1.0 specification was issued as standards-based text format for interchange of data as of February 1998.
W3C XML Working Group designed XML as a simplified subset of SGML
(c) Nizar Mabroukeh 2001 13
Standard XML specification does not define
any particular tag names (like HTML), instead it defines general syntactic rules enabling developers to create their own domain-specific vocabularies of tags.
(c) Nizar Mabroukeh 2001 14
balance sheet
total-assets
asset (current)
amount (1998)
$41,000,000
<balance-sheet><total-assets><asset-type="current">
<amount-period="1998"><amount>$41,000,000
</amount></amount-period>
</asset-type></total-assets>
</balance-sheet>
Context Greater context to the information Tree structure is natural in XML
(c) Nizar Mabroukeh 2001 15
Freedom Extensible markup language
Customized tags
Tags give meaning to the content
Separates data from style
(c) Nizar Mabroukeh 2001 16
Why XML? Derived as a subset of SGML Allows you to define your own tags
XML: <author> YAG </author>HTML: <B> YAG </B>
Provides meaningful & readable data Meaning searches can be performed Much simpler than SGML
SGML spec = 300 pages, XML = 33 pages Purely a Data Technology Supports compound documents.
(c) Nizar Mabroukeh 2001 17
XML Advantages
Web based
Extensible
License-free
Platform independent
Single end-to-end IT solution for electronic information exchanges
XML Documents
Authoring XML
(c) Nizar Mabroukeh 2001 19
XML Elements An XML element is made up of a start tag, an
end tag, and data in between. The start and end tags describe the data within the tags, which is considered the value of the element.
For example, the following XML element is a <chairman> element with the value “Sadiq Sait"
<chairman>Sadiq Sait</chairman>
Elements can be empty, to represent an empty element: <chairman/>
<book> Codebook 6.0 </book>
Opening Tag
Content Closing Tag
Element
(c) Nizar Mabroukeh 2001 21
XML Attributes An element can optionally contain one or
more attributes. An attribute is a name-value pair separated by an equal sign (=).
Example: <CITY ZIP=“31261">Dhahran</CITY>
Here, ZIP=“31261" is an attribute of the <CITY> element. Attributes are used as meta information
(c) Nizar Mabroukeh 2001 22
XML is…
…Case-sensitive
(c) Nizar Mabroukeh 2001 23
Parts of an XML document
Version Declaration
Document Type Definition (DTD)
<root>
BODY
</root>
(c) Nizar Mabroukeh 2001 24
Version Declaration
<?xml version=“1.0” encoding=“UTF-8” standalone=“yes”?>
Encoding: Supports Unicode 8, Unicode 16 & Others In short: Provides for multi-lingual data
Standalone: Indicates whether the document has any
markup declarations that are external to the document
(c) Nizar Mabroukeh 2001 25
XML data This is how XML data would look like (the
body of the document):
<books><book>
<name> Codebook 6.0 </name> <author> YAG </author> <level> Intermediate & Advanced </level>
</book><book>
<name> Jave for Beginners </name> <author> Dale </author> <level> Beginner </level>
</book></books>
(c) Nizar Mabroukeh 2001 26
XML Document Rules ONE Root element
ALL tags start AND end
Tags cannot overlap and are case sensitive
Attribute values enclosed in quotes
Attributes not repeated in an element
FIRST item must be
<books>
<book></book>
<book ISBN=“21-458-65-0”>
<para id=“1” s:id=“4”>
<?xml version=“1.0”?>
(c) Nizar Mabroukeh 2001 27
Two types of XML documents
Well-formed XML documents
Valid XML documents
(c) Nizar Mabroukeh 2001 28
Well-formed document Must contain one or more elements Must contain a uniquely named root element All other elements within the root element must
be nested correctly An XML parser will reject malformed documents
(the method of rejection will vary by parser author)
Documents that contain XML and HTML tags are common
HTML within an XML document must be well-formed
(c) Nizar Mabroukeh 2001 29
Valid XML document The XML document must be well formed Should contain a Document Type Definition
DTD is a schema which contains the constraints for the XML document
It contains Element definitions and their Attributes
Attributes should comply with the following rules Cannot contain <, & or a single ‘ or ‘’.
Elements must be nested correctly
(c) Nizar Mabroukeh 2001 30
Document Type Definition DTD is a text document that defines
the lexicon of legal names for tags in a particular XML vocabulary
It also defines how tags should be nested
It can be written as code inside the XML file or specified externally as a separate text file with extension .dtd
(c) Nizar Mabroukeh 2001 31
Sample DTD<!-- Uses EBNF (Extended Backus Naur Form) -->
<!DOCTYPE book [
<!ELEMENT book(name,author,level)+>
<!ELEMENT name(#PCDATA)>
<!ELEMENT author(#PCDATA)>
<!ELEMTNT level(#PCDATA)>
<!ATTLIST author email CDATA #IMPLIED>
]>
DTD may be specified externally with .dtd extension <!DOCTYPE book SYSTEM “book.dtd”>
(c) Nizar Mabroukeh 2001 32
More on DTD Special software can help you build your
DTD document visually instead of having to write all this weird code, example software package is “XML Authority” from Extensibility
An XML document is associated with a corresponding DTD document for validation using the <!DOCTYPE…> tag
(c) Nizar Mabroukeh 2001 33
Why use a DTD? Application independent way of
sharing data Industries or trading parties can agree
on a standard for interchanging data Verification that data received from
trading parties is valid.
(c) Nizar Mabroukeh 2001 34
Complete XML document<?xml version=“1.0” ?>
<!DOCTYPE book [
<!ELEMENT book(name,author,level?)+>
<!ELEMENT name(#PCDATA)>
<!ELEMENT author(#PCDATA)>
<!ELEMTNT level(#PCDATA)>
]>
<book>
<name> Codebook 6.0 </name>
<author> YAG </author>
<level> Intermediate & Advanced </level>
</book>
(c) Nizar Mabroukeh 2001 35
OR
<?xml version=“1.0” ?>
<!DOCTYPE book SYSTEM “book.dtd”>
<book>
<name> Codebook 6.0 </name>
<author> YAG </author>
<level> Intermediate & Advanced </level>
</book>
(c) Nizar Mabroukeh 2001 36
XML Document Pluses Tightly Structured Extensible Easily models data Useful for applications and transfer
between applications Interchangeable
XML Data Islands
XML inside HTML
(c) Nizar Mabroukeh 2001 38
XML Data Islands A data island is an XML document that
exists within an HTML page. It allows you to script against the XML
document without having to load it through script or through the <OBJECT> tag.
Almost anything that can be in a well-formed XML document can be inside a data island
(c) Nizar Mabroukeh 2001 39
How to create XML data island
The XML for a data island in HTML can be either:
Inline using ID,
or called from an outside xml file using SRC,
or created using a <script> tag
(c) Nizar Mabroukeh 2001 40
Inline data island The <XML> element marks the beginning
of the data island, and its ID attribute provides a name that you can use to reference the data island.
<XML ID="XMLID"ID="XMLID"> <customer>
<name>Mark Hanson</name> <custID>81422</custID> </customer>
</XML>
(c) Nizar Mabroukeh 2001 41
XML referenced from outside file
referenced through a SRC attribute on the <XML> tag:
<XML ID="XMLID" SRC="customer.xml"SRC="customer.xml"></XML>
(c) Nizar Mabroukeh 2001 42
Created using <script> tag
<SCRIPT LANGUAGE="xml" ID="XMLID"LANGUAGE="xml" ID="XMLID"> <customer>
<name>Mark Hanson</name> <custID>81422</custID>
</customer> </SCRIPT >
Parsing XML
(c) Nizar Mabroukeh 2001 44
What is XML Parsing For a computer program to access the
structured information in the document in a meaningful way, parsing is required
The parser first reads the stream of characters and recognizes the syntactic details of elements, attributes and text in the document
Then, the parser exposes the hierarchical set of information in the document as a tree of related elements, attributes and text items
(c) Nizar Mabroukeh 2001 45
The logical tree of information items created after parsing the XML document, is called the Information Set or Infoset
This can then be manipulated in different ways and data extracted for usage in applications, databases,…etc
(c) Nizar Mabroukeh 2001 46
XML Parsers Always check for well-formedness Can be validating or non-validating Validation required association with DTD
document Included in Microsoft Internet Explorer 5.0 Language-neutral programming model By using W3C XML 1.0 and XML DOM it
supports JavaScript, VBScript, Java, C++, Perl
(c) Nizar Mabroukeh 2001 47
Manipulating XML using the DOM
W3C provides a standard API called the Document Object Model (DOM) to access an XML document’s infoset
The DOM API provides a complete set of operations to programmatically manipulate the node tree including navigating the nodes in the hierarchy, creating and appending new nodes, removing nodes, etc.
(c) Nizar Mabroukeh 2001 48
Once you are done with making changes to the node tree you can save it and serialize the infoset back into an XML document
xml infosetparsing
serialization
(c) Nizar Mabroukeh 2001 49
DOM Properties & Methods An XML document object is created when an XML
data island is loaded and parsed…. and it has Properties & Methods
XMLDocument: Returns a reference to the XML DOM exposed by the object
documentElement: Returns the root element
childNodes: Returns a node list containing children (if any)
item(id): Access individual nodes through an index (zero based)
text Returns the text content of the node
Let’s look at an example…
(c) Nizar Mabroukeh 2001 50
DOM Example<XML ID="xmlDocument"> <class> <student studentID="13429"> <name>Jane Smith</name> <GPA>3.8</GPA> </student> </class></XML>
All of the below begin with xmlDocument.documentElement.childNodes.item(0).childNodes.item(0).text Returns "James Smith".childNodes.item(1).text Returns "3.8".text Returns "James Smith 3.8" i.e. name & GPA
Note: Everything is case sensitive hereNote: Everything is case sensitive here
Data Island
XML Presentation
Viewing XML
(c) Nizar Mabroukeh 2001 52
Viewing XML Unlike HTML, XML does not predefine
display properties for specific elements.
C++ Data Source Object (DSO) Binds XML to HTML and gives better
performance, built in IE 5.0
Cascading Style Sheets (CSS)
Extended Stylesheet Language (XSL)
(c) Nizar Mabroukeh 2001 53
CSS Separate file with a .css extension
object,+ {[property name]:[property value] ; + }
DIV {color:red; font-size:16pt}
/* Comments are entered the C way here */
(c) Nizar Mabroukeh 2001 54
Displaying XML with CSS Modify the
presentation of XML Documents
Follow normal CSS syntax
Referenced in the XML source document
paragraph{ COLOR: red; FONT-FAMILY: 'Book Antiqua'; FONT-VARIANT: small-caps; FONT-WEIGHT: bolder}preamble{ COLOR: blue; FONT-FAMILY: 'Book Antiqua'; FONT-VARIANT: small-caps; FONT-WEIGHT: bolder}
<?xml-stylesheet type="text/css" href="const.css"?>
(c) Nizar Mabroukeh 2001 55
XSL eXtended Stylesheet Language
Syntax is similar to XML
In fact, XSL is written in XML
(c) Nizar Mabroukeh 2001 56
The aim of XSL is to provide a simple but powerful stylesheet syntax, which can be used to define how XML documents should appear on the screen.
An XSL stylesheet transforms an XML document into a suitable form for presentation
It allows us to control how and which parts of the documents should be shown to the user.
(c) Nizar Mabroukeh 2001 57
The XSL processor takes an XML document as input, and translates it into a different XML document suitable for output. This resultant XML document can be passed through a separate tool to add the finishing touches ready for presentation.
(c) Nizar Mabroukeh 2001 58
Displaying XML with XSL More powerful
than CSS XSL documents
are XML documents
<xsl:for-each select=“books/book" order-by=“author">
<TR VALIGN="top" > <TD>
<xsl:value-of select="name"/>
</TD><TD><xsl:value-of
select=“author"/></TD></TR>
</xsl:for-each>
(c) Nizar Mabroukeh 2001 59
XSL Styling Tools
(c) Nizar Mabroukeh 2001 60
XSL Style Sheet
DTD
XML Document
XM
L P
arse
r
XS
L P
roce
sso
r
Web Browser
Other(e.g. Directly into
Application
Integrated use of XML
(c) Nizar Mabroukeh 2001 61
XSLT
eXtended Stylesheet Language for Transformations
Transforms XML from one tree-based structure to another
(c) Nizar Mabroukeh 2001 62
Advantages of XSLT Convert between XML vocabularies
used by different applications
Present data from an XML document by transforming it into HTML, or another format that’s appropriate to the user or special device requesting the data
Database Integration
Query and Search XML documents
(c) Nizar Mabroukeh 2001 64
XPath
XML Path Language is a W3C standard
It is a declarative language
Used to interrogate an XML document to select subsets of information
(c) Nizar Mabroukeh 2001 65
XPath provides a method for addressing parts of an XML document.
Allows string, number and boolean manipulation Treats XML document as set of nodes, allows matching
It is called a Path language because it is design like the path notation in URLs and files in directories
(c) Nizar Mabroukeh 2001 66
XPath Example/MovieList/Movie/Cast/Actor/* returns all info about all actors
/MovieList/Movie/Cast/* returns all info about Cast including that of Director and Actor and
Actress
To find attributes instead of elements we use @
/MovieList/Movie/@Title returns titles of all movies
//Actress/@Role returns the Role of any Actresses anywhere in the document
(c) Nizar Mabroukeh 2001 67
Find the Cast of any movies directed byMinghella with a running time greater than130 minutes:
/MoiveList/Movie[Director/Last=‘Manghella’ and @RunningTime >130]/Cast
(c) Nizar Mabroukeh 2001 68
Where to Use XPath<Item Context="{Xpath here}" Type="">
<Label>Your Name</Label>
<Interface>
<EditableField Duid="{Xpath here}">
<Value>Tony</Value>
</EditableField> </Interface>
</Item>
Logical:
<TD NOWRAP="NOWRAP" ALIGN="LEFT">
<INPUT TYPE="text" SIZE="48" VALUE="Tony" Name="{Xpath here}"/>
</TD>
HTML:
(c) Nizar Mabroukeh 2001 69
Using XPath Create an XPath for each unit of
information Carry the XPaths with the information as
it is transformed into other formats Use XPaths to link language strings and
labels with the information they describe
Generate an XSL stylesheet that uses the XPaths to generate the outgoing message
You should be using XML
More reasons for you to use XML
(c) Nizar Mabroukeh 2001 71
Why should I use XML XML enables a data web of
information services; it is vendor-neutral, platform-neutral, language-neutral technology
Simplifies application integration, consider the following example
(c) Nizar Mabroukeh 2001 72
Simplifies Integration If a company has:
Machines running OS from Sun, HP, IBM… Databases from Oracle, IBM, Microsoft… Packaged applications from Oracle, SAP…
An XML-based representation of data and the HTTP protocol might be the only things these various systems can ever hope to have in common!
Especially if you want to integrate them over the Internet
(c) Nizar Mabroukeh 2001 73
Why should I use XML XML also simplifies Information
Publishing and ReuseWith XML and XSLT you can easily:
• Separate data from presentation, allowing you to change the look of information without affecting application code
• Publish the same data using output styles specific to each kind of requesting device: browser, cell phone, PDA or another computer, etc.
(c) Nizar Mabroukeh 2001 74
WML: Wireless Markup Language for cell phones and PDAs
SVG: Scalable Vector Graphics language for rendering rich, data-driven images
XSL Formatting Objects: for high-quality printed output
Creating your own XML Vocabulary
(c) Nizar Mabroukeh 2001 76
XML Vocabulary The set of XML elements and
attributes for a certain application is called an XML Vocabulary
Can be used in more than one XML document for the same application
(c) Nizar Mabroukeh 2001 77
Create your own… Begin each document with an XML
decleration<?xml version=“1.0”?> (case-sensitive)
Use only one top-level document element cannot be repeated
Match opening and closing tags properly (notice case-sensetivity)
(c) Nizar Mabroukeh 2001 78
Add comments between <!-- and --> characters
Start element and attribute names with a letter. Cannot contain spaces
Put attributes in the opening tag
Enclose attribute values in matching quotes
(c) Nizar Mabroukeh 2001 79
Use only simple text as attribute values
Use < and & instead of < and & for literal less-than and ampersand characters
Write empty elements as <ElementName/>
If you follow these rules then your document will be a well-formed XML document
Review of Applications and Tools
(c) Nizar Mabroukeh 2001 81
XML Tools Help author the grammars (Schema,
Filter, Updates)
View, Edit & Manage XML
Define mappings between XML logical views & Databases.
(c) Nizar Mabroukeh 2001 82
How is XML used? Publishing
Create once, use many Database Management
Database integration e-Business
Key driver
(c) Nizar Mabroukeh 2001 83
XML Creation Tools
Two schools:
Data centric
Document centric
(c) Nizar Mabroukeh 2001 84
Microsoft XML Notepad
Free Tree-
based Great
search
msdn.microsoft.com/xml/notepad
(c) Nizar Mabroukeh 2001 85
CueSoft eXML Tree or
source view
Attribute handling
No search No nav bar
in source view
www.cuesoft.com
(c) Nizar Mabroukeh 2001 86
Techno2000 Clip! Powerful Flexible Wizards DTD
creationhttp://www.t2000-usa.com/download/download_index.html
(c) Nizar Mabroukeh 2001 87
Vervet Logic XML Pro More
expensive
www.vervetlogic.com
(c) Nizar Mabroukeh 2001 88
Document Oriented Examples
SoftQuad XMetaL Corel WordPerfect 9 Arbortext Adept Editor
Not as good for data development Require DTD or equivalent
(c) Nizar Mabroukeh 2001 89
XSL Tester
Free Open
source VB
www.vbxml.com
(c) Nizar Mabroukeh 2001 90
XML Authority from Extensibility
(c) Nizar Mabroukeh 2001 91
XML Authority from Extensibility
DTDs
Schema
(c) Nizar Mabroukeh 2001 92
Other Choices Web-based
DTD Generator• www.pault.com/Xmltube/dtdgen.html
IBM Suite Visual DTD Visual XML Transformation
(c) Nizar Mabroukeh 2001 93
Utilities
File manipulation XML Junction
• www.xmljunction.com
ODBC2XML
(c) Nizar Mabroukeh 2001 94
Security
IBM’s XML Security Suite www.alphaworks.ibm.com/tech/
xmlsecuritysuite
(c) Nizar Mabroukeh 2001 95
Programming and XML
Programming tools and environments Java including JAXP Visual Basic (VB) and Visual
Basic for Applications (VBA) Databases and other tools
Document vs. event driven processing (DOM vs. SAX)
Resources for XML
(c) Nizar Mabroukeh 2001 97
Software Sources Interesting sites
www.xmlsoftware.com
alphaworks.ibm.com
www.garshol.priv.no/download/xmltools/std_ix.html
(c) Nizar Mabroukeh 2001 98
WebSites
The Mother Ship www.w3c.org/xml
Heavy Stuff www.ibm.com/developer/xml msdn.microsoft.com/xml www.oracle.com/xml/ java.sun.com/xml/
(c) Nizar Mabroukeh 2001 99
More Resources … XML Information sites
www.xmlinfo.com www.xml.com www.xml.org www.xmlelephant.com metalab.unc.edu/xml/ www.ucc.ie/xml/
XML Tutorials www.xml101.com
(c) Nizar Mabroukeh 2001 100
More Resources … XSL Information
http://www.mulberrytech.com/xsl/xsl-list
VB XML Information mailto:[email protected]
(c) Nizar Mabroukeh 2001 101
And finally…
We’re only at the very start of the Web revolution.
XML is the fundamental building block
XML technology is moving forward, and Standards are rapidly evolving
(c) Nizar Mabroukeh 2001 102
Thank You