xml
DESCRIPTION
TRANSCRIPT
Introduction to XML
What is XML?
Extensible Markup Language
Extensible-Not fixed format like HTML
Meta language - Language for describing other languages
Enables you to define your own customized markup
Focus on what the data is
Simplified version of SGML
Why XML?
Richly structured documents could be used over the web.
Human readable and also easy to edit/view.
XML documents are language neutral.
Platform-independent.
Basic XML Rules
Xml is case sensitive
All start tags must have end tags
Elements must be properly nested
XML declaration is the first statement
Every document must contain a root element
Attribute values must have quotation marks
Certain characters are reserved for parsing
Differences between XML and HTML
Extensible Markup Language Hyper Text Markup Language
XML is designed to store the data HTML is designed to display the
data
XML focus on what the data is HTML focus on how data looks
XML allows us to define our own
tags
HTML has predefined set of tags
XML is used to transport the data HTML is used to format and
display data
XML improves the functionality of web technologies through the useof a more flexible and adaptable means to identify information .
XML is a Meta language, Language that describes other languages.
XML Benefits
XML Editors
Xml editor is a markup language editor with addedfunctionality to facilitate the editing of xml.
Xml editor should be able to
Add closing tags to your opening tags automatically Force you to write valid xmlVerify your xml against a DTDVerify your xml against a SchemaColor codes your xml syntax
Some of the professional xml editors are
EmEditor
XML Cook top
XML Pro
XML Spy
Xml tags are very similar to HTML , The difference is that xmltags are not pre-defined like HTML
Example
<Composer> is an example for an opening tag, In XML allopening tags must have closing tags, in this case the closing tagwould look like </Composer>.
XML Tags
Prolog refers to the information that appears before the start tagof the document or root element. It includes information thatapplies to the document as a whole, such as character encoding,document structure, and style sheets.
Prolog
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href=“Book.xsl"?>
<!DOCTYPE catalog SYSTEM "catalog.dtd“>
XML declaration typically appears as the first line in an XMLdocument. The XML declaration is not required, however, if used itmust be the first line in the document.
XML declaration in the document map consists
XML Declaration
Version number
<?xml version="1.0"?>
This is mandatory. Although the number might change for future versions of XML, 1.0 is the current version.
XML Declaration Con.
Encoding declaration
<?xml version="1.0" encoding="UTF-8"?>
This is optional. If used, the encoding declaration mustappear immediately after the version information in theXML declaration.
XML Declaration Con.
Standalone declaration
<?xml version="1.0" encoding="UTF-8" standalone="YES"?>
This is optional. If used, the standalone declaration must appear lastin the XML declaration.
XML Syntax Rules
Tags are case sensitive
Each document must have a root
Closing tags are required
Values must be enclosed in quotation marks
Elements must be properly nested
Entities must be declared
Tags are Case-Sensitive
<CourseName> is different from<coursename>
<Bad>This is bad XML</bad>
<Root>
<Child>
<Subchild>
</Subchild>
</Child>
</Root>
XML Documents Must Have a Root
This is bad XML<p>
This is also bad<br>
<p>This is ok</p>
This is the shortcut for an empty tag<br/>
Closing Tags are Required
<student id=1234>Bad Student!</student>
<student id="1234">Good Student</student>
Values Must be in Quotation Marks
Comments should not appear on the first line.
The string "--" (double-hyphen) is not allowed (as it is used todelimit comments), and entities must not be recognized withincomments.
Syntax for writing comments in xml is similar to that of HTML.
<! -- This is a comment -->
Comments in XML
<tag1><tag2>Badly nested!</tag1></tag2>
<tag1><tag2>Looks good!</tag2></tag1>
Elements Must be Properly Nested
Structure of XML
Structure of XML con..
<?xml version="1.0"?><note>
<To>workshop</To><From>Trainer</From><Heading>Reminder</Heading><Body>Don't forget me this weekend!</Body>
</note>
Well-formed
Valid
Invalid
Types of XML Documents
Well Formed XML
Well formed xml document does not need a DTD, but is must confirm to the xml syntax rules.
Valid XML
Valid documents confirms not only to the syntax, but also to the DTD.
Invalid XML
Neither it follows xml syntax rules nor DTD.
Follows the XML syntax rules
<?xml version="1.0"?><course><name>Markup Languages</name><number>99999</number><college>New Generation</college><credits>4</credits></course>
Well-Formed XML
<?xml version="1.0"?><!DOCTYPE course SYSTEM "courses.dtd"><course><name>Markup Languages</name><number>9999-82</number><college>New Generation</college><credits>4</credits></course>
Valid XML
Well-formed XML doc that conforms to a DTD.
<?xml version="1.0"?><course><name>Markup Languages</name><number type=2>9999-82</number><college>New Generation</college><credits>4</course>
Invalid XML
Example
What is DTD?
DTD (Document Type Definition) describes the structure of oneor more XML documents.
OR
Helps in eliminating errors when creating or editing XMLdocuments.
Building Blocks of DTD
Elements
Attributes
Entities
PCDATA
CDATA
<!ELEMENT name ANY>Creates an element which can contain both Plain text and tags
<!ELEMENT name (#PCDATA)>Creates an element which can contain plain text but NOT other tags
<!ELEMENT name EMPTY>Creates an empty element
Declaring Elements in a DTD Cont.
<!ELEMENT name (child1, child2)>Creates an element with children which must be present in theorder listed
<!ELEMENT name (child1 | child2)>Creates an element with options
Either child1 or child2 must appear, but not both.
Declaring Elements in a DTD Cont.
<!ELEMENT name (child)?>Creates an element with a child which must appear zero or one times
<!ELEMENT name (child)+>Creates an element with a child which must appear one or more times
<!ELEMENT name (child)*>Creates an element with a child which may appear zero or more times
Declaring Elements in a DTD Cont.
<!ATTLIST Target-element name Type Default>
Target-element is the element to which the attribute applies
Name is the attribute name type is what type of data the attribute contains
Default is whether the item is required
Declaring Attributes in a DTD
General form
Attribute-type can be one of the following
Type Description
CDATA The value is character data
(en1|en2|..) The value must be one from an
enumerated list
ID The value is a unique id
IDREF The value is the id of another
element
IDREFS The value is a list of other ids
NMTOKEN The value is a valid xml name
NMTOKENS The value is a list of valid xml
names
ENTITY The value is an entity
ENTITIES The value is a list of entities
NOTATION The value is a name of a notation
xml The value is a predefined xml
value
Default-value can be one of the following
Value Explanation
value The default value of the attribute
#REQUIRED The attribute is required
#IMPLIED The attribute is not required
#FIXED value The attribute value is fixed
Example
<?xml version="1.0"?><!DOCTYPE Parts [<!ELEMENT Parts (Title?, Part*)><!ELEMENT Title (#PCDATA)><!ELEMENT Part (Item, Manufacturer, Model, Cost)+><!ATTLIST Parttype (Computer|Auto|Airplane) #IMPLIED><!ELEMENT Item (#PCDATA)><!ELEMENT Manufacturer (#PCDATA)><!ELEMENT Model (#PCDATA)><!ELEMENT Cost (#PCDATA)>]>
Example cont..
<Parts><Title>Main Heading</Title><Part type="Computer"><Item></Item><Manufacture></Manufacture><Model></Model><Cost></Cost></Part></Parts>
XML-Entities
An entity is a name that represents a special character, additional text or a file.
There are two kinds of entities
General entities
Parameter entities
XML Predefined Entities
Entity Name Replacement as Text
< <
> >
& &
' ‘
" “
XML-Entities cont..
General entities: Used in the context of documents.
References to general entities start with & and end with;
Parameter entities: Used in a document’s DTD.
References to parameter entities start with % and end with;
Example
<?xml version="1.0"?><!DOCTYPE Film [<!ENTITY COM "Comedy"><!ENTITY SF "Science Fiction"><!ELEMENT Film (Title+, Genre, Year)><!ELEMENT Title (#PCDATA)><!ELEMENT Genre (#PCDATA)><!ELEMENT Year (#PCDATA)>]><Film><Title id="1">Tootsie</Title><Genre>&COM;</Genre><Year>1982</Year><Title Id="2">Jurassic Park</Title><Genre>&SF;</Genre><Year>1993</Year></Film>
DTD Classification
Internal document type definition (DTD)
External document type definition (DTD)
Internal DTD
If a DTD is used only by a single XML document, it can be put directly in that document.
Syntax
<! DOCTYPE Root-Element [DTD Specification]>
Example
<?xml version="1.0"?><!DOCTYPE Note [<!ELEMENT Note (To, From, Heading, Body)><!ELEMENT To (#PCDATA)><!ELEMENT From (#PCDATA)><!ELEMENT Heading (#PCDATA)><!ELEMENT Body (#PCDATA)>]><Note><To>Data1</To><From>Data2</From><Heading>Reminder</Heading><Body>Don't Forget Me This Weekend</Body></Note>
External DTD is one that resides in a separate document. It referssaving the DTD as a separate file with extension .dtd and thenreferencing the DTD file within the XML document.
Syntax
<! DOCTYPE Root-Element SYSTEM "File-Name">
External DTD
<?xml version="1.0"?><!DOCTYPE note SYSTEM "note.dtd"><note><to>Data1</to><from>Data2</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>
And this is the file "note.dtd" which contains the DTD
<!ELEMENT note (to, from, heading, body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>
Example
DTD’s use old SGML style definitions
DTD are not written in XML
Only defaults for attributes, not for elements
No support for Namespaces
What's wrong with DTD?
XML definition system developed to replace Document Type Definitions (DTD)
XML Schema
Be prepared quickly.
Be precise, concise, human-readable.
XML schema language specification shall
Formatting XML using CSS
What is CSS?
CSS stands for Cascading Style Sheets.
Styles define how to display (XML,HTML)elements.
External Style Sheets can save a lot of work.
External Style Sheets are stored in CSS files.
XML and CSS
XML and CSS simplify document creation. CSS, on the otherhand, makes it possible to present that document in abrowser.
Example
<?xml version=“1.0”?><?xml-stylesheet type="text/CSS" href="tutorials.CSS"?><tutorials><tutorial><name>xml Tutorial</name><url>www.testport.com</url></tutorial><tutorial><name>HTML Tutorial</name><url>www.Test IT Solutions.com</url></tutorial></tutorials>
Tutorials {Margin: 10px;Background-color: #ccff00;Font-family: veranda, Helvetica, sans-serif; }Name {Display: block;Font-weight: bold; }url {Display: block;Color: #636363;Font-size: small;Font-style: Italic;}
CSS File
Formatting XML using XSLT
What is XSLT?
Stands for XSL Transformations
Most important part of XSL
Transforms an XML document into another XML document
Uses XPath to navigate in xml documents
W3C Recommendation.
How Does it Work?
XSLT uses XPath to define parts of the source document thatshould match one or more predefined templates. When amatch is found, XSLT will transform the matching part of thesource document into the result document.
XML Technologies
What Is XHTML?
Stands for Extensible Hypertext Markup Language
Almost identical to HTML 4.01
Stricter and cleaner version of HTML
Defined as an XML application
W3C Recommendation
Combination of HTML and XML
Consists of all the elements in HTML ,Combined with thestrict syntax of XML
XHTML – Why?
What is XSL?
XSL stands for Extensible Style Sheet Language. The WorldWide Web Consortium (W3C) started to develop XSLbecause there was a need for an XML-based Style sheetLanguage.
XSLT - A language for transforming XML documents
XPath – A language for navigating in XML documents
XSL-FO - A language for formatting XML documents
XSL consists of three parts
Comparing CSS and XSLT
CSS XSLT
Simple to use, and suitable for
simple documents
Complex to use
Can’t reorder, add, delete or
perform operations on elements
Can re order, add, delete
elements
Uses less memory Uses more memory and
processor power
Does not use XML syntax Follows the XML syntax
CSS - Cascading Style Sheets for display.
XSL - Extensible Style sheet Language for display.
XSLT - XSL Transformations.
Xpath - Allows XML files to include other content.
Xlink - Allows XML files to link to other XML files.
Xquery - Allows XML files to query databases.
Other Related Technologies
Conclusion
XML is a self-descriptive language
XML is a powerful language to describe structure data forweb application
XML is currently applied in many fields
Many vendors already supports or will support XML
Thank You