+ All Categories

Xml

Date post: 15-Jan-2015
Category:
Upload: soumya
View: 828 times
Download: 1 times
Share this document with a friend
Description:
 
64
Introduction to XML
Transcript
Page 1: Xml

Introduction to XML

Page 2: 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

Page 3: Xml

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.

Page 4: Xml

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

Page 5: Xml

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

Page 6: Xml

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

Page 7: Xml

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

Page 8: Xml

Some of the professional xml editors are

EmEditor

XML Cook top

XML Pro

XML Spy

Page 9: Xml

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

Page 10: Xml

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“>

Page 11: Xml

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.

Page 12: Xml

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.

Page 13: Xml

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.

Page 14: Xml

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

Page 15: Xml

Tags are Case-Sensitive

<CourseName> is different from<coursename>

<Bad>This is bad XML</bad>

Page 16: Xml

<Root>

<Child>

<Subchild>

</Subchild>

</Child>

</Root>

XML Documents Must Have a Root

Page 17: Xml

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

Page 18: Xml

<student id=1234>Bad Student!</student>

<student id="1234">Good Student</student>

Values Must be in Quotation Marks

Page 19: Xml

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

Page 20: Xml

<tag1><tag2>Badly nested!</tag1></tag2>

<tag1><tag2>Looks good!</tag2></tag1>

Elements Must be Properly Nested

Page 21: Xml

Structure of XML

Page 22: 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>

Page 23: Xml

Well-formed

Valid

Invalid

Types of XML Documents

Page 24: Xml

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.

Page 25: Xml

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

Page 26: 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.

Page 27: Xml

<?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

Page 28: Xml

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.

Page 29: Xml

Building Blocks of DTD

Elements

Attributes

Entities

PCDATA

CDATA

Page 30: Xml

<!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.

Page 31: Xml

<!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.

Page 32: Xml

<!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.

Page 33: Xml

<!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

Page 34: Xml

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

Page 35: Xml

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

Page 36: Xml

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)>]>

Page 37: Xml

Example cont..

<Parts><Title>Main Heading</Title><Part type="Computer"><Item></Item><Manufacture></Manufacture><Model></Model><Cost></Cost></Part></Parts>

Page 38: Xml

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

Page 39: Xml

XML Predefined Entities

Entity Name Replacement as Text

&lt; <

&gt; >

&amp; &

&apos; ‘

&quot; “

Page 40: Xml

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;

Page 41: Xml

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>

Page 42: Xml

DTD Classification

Internal document type definition (DTD)

External document type definition (DTD)

Page 43: Xml

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]>

Page 44: Xml

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>

Page 45: Xml

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

Page 46: Xml

<?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

Page 47: Xml

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?

Page 48: Xml

XML definition system developed to replace Document Type Definitions (DTD)

XML Schema

Page 49: Xml

Be prepared quickly.

Be precise, concise, human-readable.

XML schema language specification shall

Page 50: Xml

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.

Page 51: Xml

XML and CSS

XML and CSS simplify document creation. CSS, on the otherhand, makes it possible to present that document in abrowser.

Page 52: Xml

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>

Page 53: Xml

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

Page 54: Xml

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.

Page 55: Xml

How Does it Work?

Page 56: Xml

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.

Page 57: Xml

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

Page 58: Xml

Combination of HTML and XML

Consists of all the elements in HTML ,Combined with thestrict syntax of XML

XHTML – Why?

Page 59: Xml

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.

Page 60: Xml

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

Page 61: Xml

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

Page 62: Xml

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

Page 63: Xml

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

Page 64: Xml

Thank You


Recommended