/
XML Extensible Markup Language is simply a set of XML Extensible Markup Language is simply a set of

XML Extensible Markup Language is simply a set of - PowerPoint Presentation

tawny-fly
tawny-fly . @tawny-fly
Follow
417 views
Uploaded On 2017-08-04

XML Extensible Markup Language is simply a set of - PPT Presentation

rulesThis set of rules identifies how you can define tags that seprate a document into individual parts and subparts XML rules are based on earlier markup language called the SGMLstandard generalized markup language which was developed to provide a method to identify the portions and con ID: 575707

rcet xml kumar lecturer xml rcet lecturer kumar sunil sahu element document xlink entity type dtd xsl documents xsd

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "XML Extensible Markup Language is simply..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

XML

Extensible Markup Language is simply a set of rules.This set of rules identifies how you can define tags that seprate a document into individual parts and subparts.XML rules are based on earlier markup language called the SGML(standard generalized markup language) which was developed to provide a method to identify the portions and content of a document,not by the actual content or line no.but by the type of information it contains.XML cretes text files to store your structured information.

1

Sunil Kumar Sahu,Lecturer RCETSlide2

XML is very easy to use ,easy to read by a

computer,easy to debug and easy to use to crate XML suitable for any industry that uses structured data such as spreadsheetdatabases,financial information and technical drawings.XML file can be saved with .xml extension.What is XML?XML stands for EXtensible Markup LanguageXML is a markup language much like HTMLXML was designed to carry data, not to display dataXML tags are not predefined. You must define your own tags

XML is designed to be self-descriptiveXML is a W3C Recommendation

2

Sunil Kumar Sahu,Lecturer RCETSlide3

The Difference Between XML and HTML

XML is not a replacement for HTML. XML and HTML were designed with different goals:XML was designed to transport and store data, with focus on what data isHTML was designed to display data, with focus on how data looks3Sunil Kumar Sahu,Lecturer RCETSlide4

XML Does Not DO Anything

Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store, and transport information.The following example is a note to Tove, from Jani, stored as XML: <?xml version =“1.0” standalone=“yes”?><note><to>Tove

</to><from>

Jani

</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

<?xml version =“1.0”?>

always appearing as the first line in xml document which specify the version of xml that is used.

<standalone=“yes ”> used to specify the relationship xml file to other file.The note above is quite self descriptive. It has sender and receiver information, it also has a heading and a message body.

4

Sunil Kumar Sahu,Lecturer RCETSlide5

With XML You Invent Your Own Tags

The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document.That is because the XML language has no predefined tags.The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.).XML allows the author to define his/her own tags and his/her own document structure.5

Sunil Kumar Sahu,Lecturer RCETSlide6

Extensible

Stylesheet Language(XSL)The Extensible Style Language (XSL) is a more advanced style-sheet language specifically designed for use with XML documents. XSL documents are themselves well-formed

XML documents.

XSL is a language for expressing style sheets. An XSL style sheet is, like with 

CSS

, a file that describes how to display an XML document of a given type

.

The XSL standards provides a framework for converting XML documents to other forms of structured text(HTML) and for studying XML documents for output to various media including print and electronic media.

6

Sunil Kumar Sahu,Lecturer RCETSlide7

The Need for XSL

CSS can not change the order of appearance of content within a document.CSS can not display attribute values,even though you can use attribute as selectors in CSS rules.CSS does not address the ongoing need for formatting documents in print.XSL is the bridge between XML and HTML7Sunil Kumar Sahu,Lecturer RCETSlide8

8

Using an XSL ProcessorXSL Processor

XML

document

XSL

stylesheet

Result is

either an

XML, HTML

or text

document

Sunil Kumar Sahu,Lecturer RCETSlide9

The XSL standard actually comprises two specification-

1.XSL Transformation(XSLT)2.XSL Formatting Objects(XSL-FO)9Sunil Kumar Sahu,Lecturer RCETSlide10

XSLT

An XSLT stylesheet is a program that transforms an XML document into another non-XML documentFor example:Transforming XML to XHTML (HTML that conforms to XML syntax)Transforming an XML document to WML (a format of XML that cellular phones can display)XSLT accomplishes the transformation using series of one or more template rule with source documents to be transformed.These template rules are fed into XSLT processor which performs the desired transformation.

10

Sunil Kumar Sahu,Lecturer RCETSlide11

An

xsl:template element consist of 2 parts-1.A match expression indicating which portion of the source document will be processed by this template rule.2.The template proper, meaning something to be instantiated or some action to take place when a matching portion of the source document is found.11Sunil Kumar Sahu,Lecturer RCETSlide12

For

eg.- Consider the following xml document.<? XML version=“1.0” ><Book> <Book_Title>Compelete Reference XML </Book_Title

> <Author> Heather Williamson</Author>

</Book>

Assume that we want to convert the above document into HTML.

Specifically the Book title will be transformed to a level-1 and author name will transformed to level-2 heading.

The following XSLT style sheet accomplish the objective.

12

Sunil Kumar Sahu,Lecturer RCETSlide13

<

xsl:stylesheet version=“1.0”xmlns:xsl=http://www.w3.org/1991/xsl/Transformxmlns:xsl=http://www.w3.org/TR/REC/Html-40><!—template rule to suppress all default text processing--><xsl:template match =“text()/”><!—template rule for processing Book element -->

<xsl:template match=“Book”>

<html>

< head> <title>Book information </title></head>

<body>

<h1><

xsl:value

-of select=“

Book_Title

”/></h1> <h2><xsl:value-of select=“Author”/></h2> <body></html></xsl:template></xsl:stylesheet>

13

Sunil Kumar Sahu,Lecturer RCETSlide14

Linking XSLT Style sheet to an XML Document-

<? Xml stylesheet type =“text/xsl”href=“URL”?>The result of passing this style sheet through XSLT processor will be the html document-<html> <head><title>Book Information</title></head> <body> <h1>Complete Reference</h1> <h2>heather Williamson</h2>

</body> </html>

14

Sunil Kumar Sahu,Lecturer RCETSlide15

XSL-FO(XSL-

Formatting Objects) :-it consist of Comprehensive set of markup that works much like CSS to render XML documents for display,print and other media.A language for formatting XML documentsUnlike CSS or XSLT style sheet, it is not linked directly to an xml document because the XSL-FO vocabulary is not meant to style another document,it styles its own documents content. Its all content comes from an XSLT style sheet.The html vocabulary consist of elements & attributes representing combination of content and presentation but XSL-FO vocabulary represents nothing but presentation.

15

Sunil Kumar Sahu,Lecturer RCETSlide16

The XSL-FO specification defines a quite large no. of elements and attributes.

We could use XSLT to transform the document to XSL-FO instead of HTMLXSL-FO documents are stored in files with a .fo or a .fob file extension. You can also store XSL-FO documents with an .xml extension (to make them more accessible to XML editors).16Sunil Kumar Sahu,Lecturer RCETSlide17

What is XSL-FO

XSL-FO is a language for formatting XML dataXSL-FO stands for Extensible Stylesheet Language Formatting ObjectsXSL-FO is based on XMLXSL-FO is a W3C RecommendationXSL-FO is now formally named XSL17Sunil Kumar Sahu,Lecturer RCETSlide18

XSL-FO Document Structure

<?xml version="1.0" encoding="ISO-8859-1"?><fo:rootxmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout-master-set>

  <fo:simple-page-master master-name="A4">

    <!-- Page template goes here -->

  </

fo:simple

-page-master>

</

fo:layout

-master-set>

<fo:page-sequence master-reference="A4">  <!-- Page content goes here -->

</fo:page

-sequence>

</

fo:root

>

18

Sunil Kumar Sahu,Lecturer RCETSlide19

Structure explained

XSL-FO documents are XML documents, and must always start with an XML declaration:<?xml version="1.0" encoding="ISO-8859-1"?>The <fo:root> element is the root element of XSL-FO documents. The root element also declares the namespace for XSL-FO:<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">  <!-- The full XSL-FO document goes here -->

</

fo:root

>

The <fo:layout-master-set> element contains one or more page templates:

<

fo:layout

-master-set>

  <!-- All page templates go here -->

</fo:layout-master-set>19

Sunil Kumar Sahu,Lecturer RCETSlide20

Each <

fo:simple-page-master> element contains a single page template. Each template must have a unique name (master-name):<fo:simple-page-master master-name="A4">  <!-- One page template goes here --></fo:simple-page-master>One or more <fo:page

-sequence> elements describe the page contents. The master-reference attribute refers to the simple-page-master template with the same name:<

fo:page

-sequence master-reference="A4">

  <!-- Page content goes here -->

</

fo:page

-sequence>

Note

: The master-reference "A4" does not actually describe a predefined page format. It is just a name. You can use any name like "MyPage", "MyTemplate", etc.

20Sunil Kumar Sahu,Lecturer RCETSlide21

XSL-FO Output

XSL-FO output is normally nested inside <fo:block> elements, nested inside <fo:flow> elements, nested inside <fo:page-sequence> elements: Example<?xml version="1.0" encoding="ISO-8859-1"?><fo:root

xmlns:fo

="http://www.w3.org/1999/XSL/Format">

<

fo:layout

-master-set>

  <

fo:simple

-page-master master-name="A4">

    <fo:region-body />

  </fo:simple

-page-master>

</

fo:layout

-master-set>

<

fo:page

-sequence master-reference="A4">

  <

fo:flow

flow-name="

xsl

-region-body">

    <

fo:block

>Hello HOW ARE YOU</

fo:block

>

  </

fo:flow

>

</

fo:page

-sequence>

</

fo:root

>

21

Sunil Kumar Sahu,Lecturer RCETSlide22

The output from this code would be something like this:

Hello HOW ARE YOU22Sunil Kumar Sahu,Lecturer RCETSlide23

DTD(Document Type Definition)

A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:ElementsAttributes, andEntitiesDTD provide the rules by which information within your XML document can be validated.It can be internal or external.

An XML document is well-structured if it follows certain simple syntactic rules.

An XML document is

valid

if it also specifies and conforms to a DTD.

Only the valid documents are valuable in terms of sharing and retrieving information.

23

Sunil Kumar Sahu,Lecturer RCETSlide24

XML documents are designed to be processed by computer programs

If you can put just any tags in an XML document, it’s very hard to write a program that knows how to process the tagsA DTD specifies what tags may occur, when they may occur, and what attributes they may (or must) have.A DTD allows the XML document to be verified (shown to be legal)A DTD that is shared across groups allows the groups to produce consistent XML documents.24

Sunil Kumar Sahu,Lecturer RCETSlide25

A

validating parser is an XML parser that compares the XML document to a DTD and reports any errorsMost browsers don’t use validating parsersDTD(Document Type Definition)25Sunil Kumar Sahu,Lecturer RCETSlide26

An XML example

<novel>

<foreword>

<paragraph>

This is the great American novel.

</ paragraph>

</foreword>

<chapter number="1">

<paragraph>

It was a dark and stormy night.

</paragraph>

<paragraph>

Suddenly, a shot rang out!

</paragraph>

</chapter>

</novel>

An XML document

contains-

Elements, such as

novel

and

paragraph

, consisting of

tags

and

content

Attributes, such as

number="1"

, consisting of a

name

and a

value

Entities (not used in this example)

26

Sunil Kumar Sahu,Lecturer RCETSlide27

A DTD example

<!DOCTYPE novel [

<!ELEMENT novel (foreword, chapter+)>

<!ELEMENT foreword (paragraph+)>

<!ELEMENT chapter (paragraph+)>

<!ELEMENT paragraph (#PCDATA)>

<!ATTLIST chapter number CDATA #REQUIRED>

]>

A

novel

consists of a

foreword

and one or more

chapter

s, in that order

Each

chapter

must have a

number

attribute

A

foreword

consists of one or more

paragraph

s

A

chapter

also consists of one or more

paragraph

s

A

paragraph

consists of

parsed character

data.

27

Sunil Kumar Sahu,Lecturer RCETSlide28

PCDATA

PCDATA means parsed character data,Think of character data as the text found between the start tag and the end tag of an XML element.PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser for entities and markup.Tags inside the text will be treated as markup and entities will be expanded.However, parsed character data should not contain any &, <, or > characters; these need to be represented by the &amp; &lt; and &gt; entities, respectively.

CDATACDATA means character data.CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as

markup

and entities will not be expanded.

28

Sunil Kumar Sahu,Lecturer RCETSlide29

#PCDATA

describes elements with only character data#PCDATA can be used in an “or” grouping:<!ELEMENT note (#PCDATA|message)*>This is called mixed contentAttributesAttributes provide 

extra information about elements.Attributes are always placed inside the opening tag of an element.In XML:

<dog name="Spot" age="3"></dog>

In DTD:

<!ATTLIST dog

name CDATA #REQUIRED

age CDATA #IMPLIED >

29

Sunil Kumar Sahu,Lecturer RCETSlide30

30

Types of DTDInternal DTDDTD is created within the XML document itself.External DTDInstead of copying the DTD into each document, you create an external file that contains the DTD.Reference its URL for each document that uses

it.

Sunil Kumar Sahu,Lecturer RCETSlide31

Internal DTD

31Sunil Kumar Sahu,Lecturer RCETSlide32

External DTD

Create a new text file with any text editorDefine the rules of the DTD.Save file as text only with the (.dtd) extension.32Sunil Kumar Sahu,Lecturer RCETSlide33

Linking to Document Type Definition

<?xml version="1.0"?><!DOCTYPE note SYSTEM “note.dtd"><note>

<to>Ken Anderson</to> <from>Lukasz Kurgan</from>

<text>Ok! We can see some progress</text>

</note>

The SYSTEM declaration identifies this DTD as being part of

local,or

nonpublic selection of DTD and use

PUBLIC

for official, published DTDs. And also with PUBLIC we use full path URL of the

document.like "http://www.mysite.com/mydoc.dtd">33

Sunil Kumar Sahu,Lecturer RCETSlide34

Another example: XML

<?xml version="1.0"?><!DOCTYPE weatherReport SYSTEM "http://www.mysite.com/mydoc.dtd"><weatherReport> <date>

05/29/2002</date>

<location>

<city>

Philadelphia

</city>

,

<state>PA</state> <country>

USA</country>

</location>

<temperature-range>

<high

scale="F"

>

84

</high>

<low

scale="F"

>

51

</low>

</temperature-range>

</weatherReport>

34

Sunil Kumar Sahu,Lecturer RCETSlide35

The DTD for this example

<!ELEMENT weatherReport (date, location, temperature-range)><!ELEMENT date (#PCDATA)><!ELEMENT location (city, state, country)>

<!ELEMENT city (#PCDATA)>

<!ELEMENT state (#PCDATA)>

<!ELEMENT country (#PCDATA)>

<!ELEMENT temperature-range

((low, high)|(high, low))>

<!ELEMENT low (#PCDATA)>

<!ELEMENT high (#PCDATA)>

<!ATTLIST low scale (C|F) #REQUIRED>

<!ATTLIST high scale (C|F) #REQUIRED>

35

Sunil Kumar Sahu,Lecturer RCETSlide36

Limitations of DTDs

DTDs are a very weak specification languageYou can’t put any restrictions on element contentsIt’s difficult to specify:All the children must occur, but may be in any orderThis element must occur a certain number of timesThere are only ten data types for attribute valuesBut most of all: DTDs aren’t written in XML!If you want to do any validation, you need one parser for the XML and another for the DTDThis makes XML parsing harder than it needs to beThere is a newer and more powerful technology:

XML SchemasHowever, DTDs are still very much in use

36

Sunil Kumar Sahu,Lecturer RCETSlide37

XML Namespace

The purpose of XML Namespaces is to distinguish between duplicate element and attribute names.In order to give documents the ability to use multiple elements of the same name within the same document,XML namespace was created.For example:<vehicles>

<sedans><price>$</price></sedans> <trucks><price>$</price></trucks>

</vehicles>

Both “sedans” and “trucks” have the same “price”

element, so the parser doesn’t know which one is which.

37

Sunil Kumar Sahu,Lecturer RCETSlide38

Notation for Namespace-

<element name xmlns:prefix=“URL”>Namespace is a mapping between an element prefix and a URL.For eg.cars is the prefix in this example, <cars:part

xmlns:cars

=“URL”>

URLs are not a pointer to information about the Namespace. They are just unique identifiers. You cannot resolve XML namespace URIs.

38

Sunil Kumar Sahu,Lecturer RCETSlide39

Ways to Specify Namespaces

1.Inside the XML file.2.Inside the DTD file.39Sunil Kumar Sahu,Lecturer RCETSlide40

This XML carries HTML table information:

<table>  <tr>    <td>Apples</td>    <td>Bananas</td>  </tr></table>This XML carries information about a table (a piece of furniture): <table>  <name>African Coffee Table</name>

  <width>80</width>  <length>120</length>

</table>

1.Inside the XML File

40

Sunil Kumar Sahu,Lecturer RCETSlide41

If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning.

An XML parser will not know how to handle these differences.Name conflicts in XML can easily be avoided using a name prefix.When using prefixes in XML, a so-called namespace for the prefix must be defined.41Sunil Kumar Sahu,Lecturer RCETSlide42

<root>

<h:table xmlns:h="http://www.w3.org/TR/html4/">  <h:tr>    <h:td>Apples</h:td>    <h:td>Bananas</h:td>  </h:tr></h:table><f:table xmlns:f="http://www.w3schools.com/furniture">  <f:name>African Coffee Table</f:name>  <f:width>80</f:width>

  <f:length>120</f:length></f:table></root>

42

Sunil Kumar Sahu,Lecturer RCETSlide43

In the example above, the

xmlns attribute in the <table> tag give the h: and f: prefixes a qualified namespace.When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace.Namespaces can be declared in the elements where they are used or in the XML root element.43Sunil Kumar Sahu,Lecturer RCETSlide44

<root 

xmlns:h="http://www.w3.org/TR/html4/"xmlns:f="http://www.w3schools.com/furniture"><h:table>  <h:tr>    <h:td>Apples</h:td>    <h:td>Bananas</h:td>  </h:tr>

</h:table><f:table>

  <f:name>African Coffee Table</f:name>

  <f:width>80</f:width>

  <f:length>120</f:length>

</f:table>

</root>

44

Sunil Kumar Sahu,Lecturer RCETSlide45

Default Namespaces

Defining a default namespace for an element saves us from using prefixes in all the child elements. It has the following syntax: xmlns="namespaceURI"Default namespace affects element names only; it does not apply to attributes.In long documents with a lot of markup, all in the same namespace, you might find it inconvenient to add a prefix to each element name. You can attach a default namespace to an element and its child elements using an

xmlns attribute with no prefix.

45

Sunil Kumar Sahu,Lecturer RCETSlide46

This XML carries HTML table information

: <table xmlns="http://www.w3.org/TR/html4/">  <tr>    <td>Apples</td>    <td>Bananas</td>  </tr></table>

This XML carries information about a piece of furniture: <table

xmlns

="http://www.w3schools.com/furniture">

  <name>African Coffee Table</name>

  <width>80</width>

  <length>120</length>

</table>

46

Sunil Kumar Sahu,Lecturer RCETSlide47

A Namespace specification can be overridden using

the prefixes.<lower:aaa xmlns:lower="http://website/lowercase"> <

lower:bbb>

<

lower:ccc

xmlns:lower

="http://website/uppercase">

<

lower:ddd>It’s uppercase now.</lower:ddd

> </

lower:ccc

>

</

lower:bbb

>

</

lower:aaa

>

47

Sunil Kumar Sahu,Lecturer RCETSlide48

2.Inside the DTD

FileHere is a sample Namespace specification within a DTD.< !DOCTYPE Vehicles [ ><!ELEMENT cars(sedans,trucks)>

<ELEMENT sedans(price)>

<ELEMENT trucks (price)>

<ELEMENT price (#PCDATA)>

<!ATTLIST cars

xmlns:part

CDATA #FIXED

“http

://

www.w3.org/1999/cars” > ] >

48

Sunil Kumar Sahu,Lecturer RCETSlide49

XML Schema

XML Schema documents are used to define and validate the content and structure of XML data.Schema provide a means of defining the structure,content and semantics of XML documents that can be shared between many types of computers and documents.XML Schemas are based on XML so like XML they can be created in a simple text editor or by one of available development programs that are availabe through internet.

It can be saved with .xsd extension.

49

Sunil Kumar Sahu,Lecturer RCETSlide50

XML Schema was originally proposed by Microsoft, but became an official W3C recommendation in May 2001.

Diffrence between DTD and Schema 1)DTD are focused on providing simple data typing on attributes and elements of XML documents while XML schema provides a systematic data typing capability. 2) DTD provide a basic macro facility using parameter entities, XML Schema allow you to re- create these effects using a system of high level built in features.

50

Sunil Kumar Sahu,Lecturer RCETSlide51

Schema Workflow

51Sunil Kumar Sahu,Lecturer RCETSlide52

Example

-<book

isbn

=“123456">

<title>

Computer Concept and Web Technology

</title>

<

author>Williamson

</

author

>

<

qualification

> PHD

</qualification

>

</book

>

 

52

Sunil Kumar Sahu,Lecturer RCETSlide53

<?xml version="1.0" encoding="utf-8"?>

<xsd:schema xmlns:xsd

="http://www.w3.org/2001/XMLSchema">

<

xsd:

element

name="book">

<

xsd:complexType

>

<

xsd:sequence

>

<

xsd:element

name="title" type="

xsd:string

"/>

<

xsd:element

name="author" type="

xsd:string

"/>

<

xsd:element

name=“qualification“ type=“

xsd:string

”/>

</

xsd:sequence

>

<

xsd:attribute

name=“

isbn

” type=“

xsd:string

”>

</

xsd:complexType

>

</

xsd:

element

>

</

xsd:

schema

>

Save as Book.xsd

The use of <sequence >element defines the order of the child elements.

53

Sunil Kumar Sahu,Lecturer RCETSlide54

Element types

Schema breaks your XML document elements into 2 types 1.complex types 2.simple types1.Complex types-Complex types of elementes,which enable attribute and elements in their content are created using <complexType> schema element declaration. 54

Sunil Kumar Sahu,Lecturer RCETSlide55

Inheritance

Each complex type definition is either

a

restriction

of a complex type definition

an

extension

of a simple or complex type definition

a

restriction

of the

ur-type definition

.

Example

<

xsd:complexType

name=

"

personName

">

<

xsd:sequence

>

<

xsd:element

name="title"

minOccurs

="0"/>

</

xsd:sequence

>

</

xsd:complexType

>

<

xsd:complexType

name="

extendedName

">

<

xsd:complexContent

>

<

xsd:extension

base="

personName

">

<

xsd:sequence

>

<

xsd:element

name="generation"

minOccurs

="0"/>

</

xsd:sequence

>

</

xsd:extension

>

</

xsd:complexContent

>

</

xsd:complexType

>

55

Sunil Kumar Sahu,Lecturer RCETSlide56

Type Definitions

Simple Type Definition VS. Complex Type DefinitionAttributes & Elements without element children

Complex Type

Definition

Simple Type

Definition

Elements

56

Sunil Kumar Sahu,Lecturer RCETSlide57

Simple Type Definition

Simple Type

Definition can be:

a

restriction

of some other simple type;

a list or union of simple type

definition;or

a built-in primitive

datatypes

.Example

<

xsd:simpleType

name="

farenheitWaterTemp

">

<

xsd:restriction

base="

xs:number

">

<

xsd:fractionDigits

value="2"/>

<

xsd:minExclusive

value="0.00"/>

<

xsd:maxExclusive

value="100.00"/>

</

xsd:restriction

>

</

xsd:simpleType

>

 

57

Sunil Kumar Sahu,Lecturer RCETSlide58

Advantages of Schema

Syntax in XML Style.Supporting Namespace and import/includeMore data types.Able to create complex data type by inheritanceInheritance by extension or restriction.

58

Sunil Kumar Sahu,Lecturer RCETSlide59

Problems of XML Schema

General ProblemSeveral-hundred-page spec in a very technical languagePractical Limitations of expressibilitycontent and attribute declarations cannot depend on attributes or element context. Technical ProblemThe notion of “type” adds an extra layer of confusing complexity

59

Sunil Kumar Sahu,Lecturer RCETSlide60

Extensible linking Language (XLL)

XLL stands for Extensible Linking language and consists of the following parts: XLink - Advanced linking. It links to multiple destinations, is bi-directional and allows for links to be displayed on other documents. XPointer - It is built on XPath and it establishes a common system to specify node locations. It allows for locating data that is not a complete node. 60

Sunil Kumar Sahu,Lecturer RCETSlide61

XLINK(XML Linking Language

)XLink is short for XML Linking LanguageDefine link relationships among more than two resources.XLink is capable of linking more than just documents; XLink links resources which includes documents,audio,video,database data,etc.

XLink is used to create hyperlinks in XML documents Any element in an XML document can behave as a link.

61

Sunil Kumar Sahu,Lecturer RCETSlide62

XLink

is a W3C Recommendation. XLink supports simple links (like HTML) and extended links (for inking multiple resources together) With XLink, the links can be defined outside the linked files.Web Browsers will eventually support XLink. However,XLink is intended for a broader base of applications, not just Web browsers. Xlink elements that specify linking information are called linking elements.

62

Sunil Kumar Sahu,Lecturer RCETSlide63

Xlink

allow XML document to- 1.Create a relationship of links between multiple documents. 2.Add information about the link to a link(metadata). 3. Create and describe links to documents in a myriad of locations.63Sunil Kumar Sahu,Lecturer RCETSlide64

Xlink

Namespace The XML Namespace specification controls how declaration of other standardized documents or document defining elements and attributes used within an XML document must be referenced. <xmlns:xlink=“http://www.w3.org/1991/xlink”> the xlink prefix is the standard method of referring to the Xlink namespace in XML documents.64

Sunil Kumar Sahu,Lecturer RCETSlide65

Xlink

Attribute- type-specifies the type of link to be created. href-specifies the address of the link. role-Specifies the type of resource that defines the destination of the link. arcrole-Specifies the type of resource that defines the source of the link. title-Describes the meaning of a link.

show-Specifies how the destination resource should be displayed.

actuate

-Specifies when the link should be traversed.

label

-Specifies an identifiable name for the link.

From

-

Refrences a label of a link to use as a reference point in the traversal of the current link.To-References a label of a link to use as a destination reference point in the traversal of the current link.65Sunil Kumar Sahu,Lecturer RCETSlide66

Types of Links

1.Simple Links 2.Extended LinksSimple Links:-Define a one-way connection between two resources.One resource is an xml element and the other is remote. This is the only link that looks like the html anchor element.Simple Links are always outbound.66Sunil Kumar Sahu,Lecturer RCETSlide67

Simple link Example-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <novel xmlns:xlink= "http://www.w3.org/1999/xlink" xlink:type = "simple“ xlink:href = "ftp://archive.org/pub/etext/my.txt"> <title>The Wonderful Wizard of Oz</title> <author>L. Frank Baum </author>

<year>1900</year> </novel>

67

Sunil Kumar Sahu,Lecturer RCETSlide68

simple - Link

ExampleXML Document<doc …xmlns:xlink=“…/xlink”>…

<mytag

xlink:type

=“simple”

xlink:role

=“

role_uri

” xlink:href=“ref_uri”

xlink:show=“new”

xlink:actuate

=“

onLoad

”>

</

mytag

>

</doc>

Role definition

Linked resource

Instruction to open the link in a new window when the link is traversed

Instruction to traverse the link when loading the original document

68

Sunil Kumar Sahu,Lecturer RCETSlide69

2.

Extended Link:-Define a collection of resources and links between them. These may be used to define a directed, labeled graph. It provides complex linking relationship among multiple resources including both inbound(arriving from another destination) and outbound(departing for a another destination) arcs.69Sunil Kumar Sahu,Lecturer RCETSlide70

Extended links will normally contain the following:-

Local resources involved in the connections. These have type=“resource” Remote resources involved in the connections. These have type=“locator” Descriptions of the connections,These have type=“arc”An element with XLink type=“title” only has XLink specified meaning if it is the child of an element with an

XLink type of extended, locator, or

arc

An element with

XLink

type=“none”

has no

XLink

specified meaning.

70Sunil Kumar Sahu,Lecturer RCETSlide71

71

Example of extended links<program xlink:type=“extended”>

</program>

<course

xlink:

type

=“resource

xlink:label

= “LA100”> Linear Algebra</course

>

<course

xlink:

type

=“resource

xlink:

label

= “LA200

”>

Linear Algebra II

</course

>

<prerequisite

xlink:

type

=“arc

xlink:

from

=“LA100

xlink:

to

=“LA200

” />

Sunil Kumar Sahu,Lecturer RCETSlide72

XPOINTER

Xpointer stands for XML Pointer Language.XPointer, defines an addressing scheme for individual parts of an XML document. XLinks point to a URL that specifies a particular resource. The URL may include an XPointer part that more specifically identifies the desired part or element of the targeted resource or document.It allow you to identify fragments or individual parts of XML documents for linking purpose which can be used by any Uniform Resource Identifier(URI) reference to locate Internet media Resource type such as text,images,or

applications.Xpointer can be used to identify the specific strings and content of a document.

72

Sunil Kumar Sahu,Lecturer RCETSlide73

The

XPointer extension to XPath allows it to- 1.Address point,ranges and nodes. 2.using string matching to locate information. 3.using addressing expression in URI references as identifiersof fragments. If the hyperlink points to an XML document, we can add an XPointer part after the URL in the xlink:href attribute,to navigate (with an

XPath expression) to a specific place in the document.XPointer Example-

In this example, we will show you how to use

XPointer

in conjunction with XLink

to point to a specific part of another document.

73

Sunil Kumar Sahu,Lecturer RCETSlide74

We will start by looking at the target XML document-

The target XML document is called “colleges.xml" <?xml version="1.0" encoding="ISO-8859-1"?> <Colleges> <college name="RCET" id=“OLD"> <picture url="http://rcet.ac.in" /> <history>RCET college is famous in chhattisgarh

</history> </college>

<college name="REC" id=“NEW">

<picture

url

="http://rcet.ac.in" />

<history>REC college is the new college in the field of engineering in

chhattisgarh

</history>

</college> <Colleges>

74

Sunil Kumar Sahu,Lecturer RCETSlide75

Note that the XML document above uses id attributes on each element we may want to link to!

To link to a specific part of a page, add a number sign (#) and an XPointer expression after the URL in the xlink:href attributes.The expression: #xpointer(id(“OLD")) refers to the element in the target document, with the id value of“OLD".So the xlink:href attribute would look like this:

xlink:href=http://rungta.ac.in/colleges.xml#xpointer(id(‘OLD'))

However,

XPointer

allows a shorthand form when linking to an element with an id. You can use the value of the id directly, like this:

xlink:href

="

http://rungta.ac.in/colleges.xml#OLD

75

Sunil Kumar Sahu,Lecturer RCETSlide76

The following XML document refers to information of the Colleges for each of my college, all through

XLink and XPointer references: <?xml version="1.0" encoding="ISO-8859-1"?> <mycolleges xmlns:xlink="http://www.w3.org/1999/xlink"> <

mycollege

xlink:type

="simple"

xlink:href

="http://rungta.ac.in/colleges.xml#OLD">

</

mycollege

> <mycollege xlink:type="simple"

xlink:href="http://rungta.ac.in/colleges.xml#NEW">

</

mycollege

>

</

mycolleges

>

76

Sunil Kumar Sahu,Lecturer RCETSlide77

Entities

Entities are placeholders in XML. You declare an entity in the document prolog or in a DTD, and you can refer to it many times in the document.Different types of entities have different uses. You can substitute characters that are difficult or impossible to type with character entities.You can pull in content that lives outside of your document with external entities. And rather than type the same thing over and overvagain, such as boilerplate text, you can instead define your own general entities.The storage unit that contains the XML declaration, the document type declaration, and the root element is called the document entity.

77

Sunil Kumar Sahu,Lecturer RCETSlide78

An entity consists of a name and a value. When an XML parser begins to process a document, it first reads a series of

declarations, some of which define entities by associating a name with a value.The value is anything from a single character to a file of XML markup. As the parser scans the XML document, it encounters entity references, which are special markers derived from entity names.For each entity reference, the parser consults a table in memory for something with which to replace the marker78

Sunil Kumar Sahu,Lecturer RCETSlide79

It replaces the entity reference with the appropriate replacement text or

markup, then resumes parsing just before that point, so the new text is parsed too. Any entity references inside the replacement text are also replaced; this process repeats as many times as necessary.79Sunil Kumar Sahu,Lecturer RCETSlide80

Types of entities

1.General entities for use in document 1.Internal 2.External Example of use: &entity;2.Parameter entities for use in DTD 1.Internal 2.External Example of use: %entity;

80Sunil Kumar Sahu,Lecturer RCETSlide81

General entity

It is used to add content to XML documents by substituting information for the entity reference that is used within the document.General entity references begin with an ampersand (&) and end with a semicolon(;), with the entity’s name between these two characters.internal general entityInternal entities are defined completely within the document and external entities draw their content from another resource located via a URL.Internal general entity references are defined in the DTD with the <!ENTITY> tag, which has the following format:

<!ENTITY entity

name “entity-value”>

81

Sunil Kumar Sahu,Lecturer RCETSlide82

Example:-

<?xml version=”1.0” standalone=”yes”?> <!DOCTYPE DOCUMENT [ <!ENTITY DV “Document Verification”> <!ELEMENT DOCUMENT (TITLE, SIGNATURE)> <!ELEMENT TITLE (#PCDATA)> <!ELEMENT COPYRIGHT (#PCDATA)> <!ELEMENT EMAIL (#PCDATA)> <!ELEMENT LAST_MODIFIED (#PCDATA)> <!ELEMENT SIGNATURE (COPYRIGHT, EMAIL, LAST_MODIFIED)> ]> <DOCUMENT>

<TITLE>&DV;</TITLE> <SIGNATURE> <COPYRIGHT>1999 &DV;</COPYRIGHT>

<EMAIL>rcet@rungta.ac.in</EMAIL>

<LAST_MODIFIED>March 10, 1999</LAST_MODIFIED>

</SIGNATURE>

</DOCUMENT>

82

Sunil Kumar Sahu,Lecturer RCETSlide83

Predefined General Entity

XML predefines five general entity references, as listed in Table 9-1. These five entity references appear in XML documents in place of specific characters that would otherwise be interpreted as markup. For instance, the entity reference &lt; stands for the less-than sign (<), which could be interpreted as the beginning of a tag.you should declare these references in your DTD if you plan to use them.To declare these references, use character references containing the hexadecimal ASCII value of each character. Listing 9-2 shows the necessary declarations:83

Sunil Kumar Sahu,Lecturer RCETSlide84

84

Sunil Kumar Sahu,Lecturer RCETSlide85

External general entity:-

External general entity references are replaced by the data at a URL specified in the entity declaration after the SYSTEM keyword.For example, you may want to put the same signature block on almost every page of a site.Let’s assume that you can retrieve this code from the URL http://metalab.unc.edu/xml/signature.xml.

85

Sunil Kumar Sahu,Lecturer RCETSlide86

Associate this file with the entity reference &SIG; by adding the following declaration to the DTD:

<!ENTITY SIG SYSTEM “http://metalab.unc.edu/xml/signature.xml”>86Sunil Kumar Sahu,Lecturer RCETSlide87

Aside from the addition of the external entity reference, note that the standalone attribute of the XML declaration now has the value no because this file is no longer complete.

Parsing the file requires additional data from the external file signature.xmlFormat for creating external general entity. <!ENTITY entity name SYSTEM “entity URL”>87Sunil Kumar Sahu,Lecturer RCETSlide88

Parameter entity

General entities become part of the document, not the DTD. They can be used in the DTD but only in places where they will become part of the document body.Parameter entities,like general entities are used to insert additional information into a document but are defined and used only in external DTD’s.For this purpose, XML provides the parameter entity reference.88Sunil Kumar Sahu,Lecturer RCETSlide89

Parameter entity references are very similar to general entity references—with these two key differences:

1. Parameter entity references begin with a percent sign (%) rather than an ampersand (&).2. Parameter entity references can only appear in the DTD, not the document content.Parameter entities are declared in the DTD like general entities with the addition of a percent sign before the name. The syntax looks like this: <!ENTITY % entity name “entity defination”>89

Sunil Kumar Sahu,Lecturer RCETSlide90

Internal parameter entity

Internal parameter entity references have the form %name; and are used exclusively in DTDs.The name is the abbreviation for the entity. The reader sees the replacement text,which must appear in quotes. For example: <!ENTITY % elist “ITEMS,TAX,SHIPPING,TOTAL”> <!ELEMENT ORDER (%elist;)><!ELEMENT CREDIT_STATEMENT (%elist;)>

90Sunil Kumar Sahu,Lecturer RCETSlide91

External parameter entities

External parameter entities enable you to build large DTDs from smaller ones. That is, one external DTD may link to another and in so doing pull in the elements and entities declared in the first.For Example-you have to need two entity statements. <!ENTITY % company SYSTEM “company.dtd”> <!ENTITY % customer SYSTEM “customer.dtd”>The company.dtd file would include the element and entity declaration used by the company recrods.91

Sunil Kumar Sahu,Lecturer RCETSlide92

<!ELEMENT COMPANY (COMPANY_NAME,ADDRESS,PHONE,FAX)>

<!ELEMENT COMPANY_NAME(#PCDATA)<!ELEMENT ADDRESS (#PCDATA)><!ELEMENT PHONE(#PCDATA)><!ELEMENTFAX(#PCDATA)>The customer.dtd statements needs to include the element declaration and entity reference used to define the customer records.<!ENTITY % clist “ CUST_NAME,CUST_ADD,CUST_CITY”>92

Sunil Kumar Sahu,Lecturer RCETSlide93

<!ELEMENT CUSTOMER (%

clist)><!ELEMENT CUST_NAME(#PCDATD)><!ELEMENT CUST_ADD(#PCDATD)><!ELEMENT CUST_CITY(#PCDATD)>Once the company and customer DTD’s are created you can start creating the primary XML documents DTD.The complete DTD for this document is given-<!ENTITY % company SYSTEM “company.dtd”> <!ENTITY % customer SYSTEM “customer.dtd”>%customer;%company;

93

Sunil Kumar Sahu,Lecturer RCETSlide94

<!ELEMENT STATEMENT

(COMPANY,CUSTOMER,SALES,OPENING,CLOSING)><!ELEMENT OPENING (#PCDATA)><!ELEMENT SALES (INVOICE+,PAYMENTS)> <!ELEMENT INVOICE (INV_NO,INV_DATE)> <!ELEMENT INV_NO(#PCDATA)> <!ELEMENT INV_DATE (#PCDATA)> <!ELEMENT PAYMENTS (P_NO,P_DATE)> <!ELEMENT P_NO(#PCDATA)> <!ELEMENT P_DATE(#PCDATA)><!ELEMENT CLOSING (#PCDATA)>

94

Sunil Kumar Sahu,Lecturer RCETSlide95

XPath

W3C has issued the Xpath as a means of locating any single unit of content ,any node within an xml document.XPath is used to navigate through elements and attributes in an XML document.XPath is a major element in W3C's XSLT standard - and XQuery and XPointer are both built on XPath

expressions.What is Xpath?

XPath

is a syntax for defining parts of an XML document.

XPath

uses path expressions to navigate in XML documents.

XPath

contains a library of standard functions

XPath

is a major element in XSLT.XPath is a W3C recommendation.95Sunil Kumar Sahu,Lecturer RCETSlide96

Fig.Xpath

,XSLT and XLink96Sunil Kumar Sahu,Lecturer RCETSlide97

XPath

Path Expressions XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system.XPath Standard Functions XPath includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more

97Sunil Kumar Sahu,Lecturer RCETSlide98

XPath

is Used in XSLT XPath is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents98Sunil Kumar Sahu,Lecturer RCETSlide99

XPath

TerminologyNodesIn XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes.XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.Look at the following XML document:<?xml version="1.0" encoding="ISO-8859-1"?><bookstore>  <book>

    <title lang="en">Harry Potter</title>

    <author>J K. Rowling</author>

    <year>2005</year>

    <price>29.99</price>

  </book>

</bookstore>

99

Sunil Kumar Sahu,Lecturer RCETSlide100

Example of nodes in the XML document above:

<bookstore> (root element node)<author>J K. Rowling</author> (element node)lang="en" (attribute node)Atomic valuesAtomic values are nodes with no children or parent.Example of atomic values:J K. Rowling"en“ItemsItems are atomic values or nodes.

100

Sunil Kumar Sahu,Lecturer RCETSlide101

101

Sunil Kumar Sahu,Lecturer RCETSlide102

102

Sunil Kumar Sahu,Lecturer RCETSlide103

Xpath

Syntax103Sunil Kumar Sahu,Lecturer RCETSlide104

104

Sunil Kumar Sahu,Lecturer RCETSlide105

105

Sunil Kumar Sahu,Lecturer RCETSlide106

106

Sunil Kumar Sahu,Lecturer RCETSlide107

107

Sunil Kumar Sahu,Lecturer RCETSlide108

XPath

Examples-Loading the XML DocumentUsing XMLHttpRequest to load XML documents is supported in all modern browsers.Code for most modern browsers: var xmlhttp=new XMLHttpRequest()

Code for old Microsoft browsers (IE 5 and 6): var

xmlhttp

=new

ActiveXObject

("

Microsoft.XMLHTTP

")

Selecting NodesInternet Explorer uses the selectNodes() method to select nodes from the XML document:xmlDoc.selectNodes(xpath);

108

Sunil Kumar Sahu,Lecturer RCETSlide109

Firefox, Chrome, Opera and Safari use the evaluate() method to select nodes from the XML document:

xmlDoc.evaluate(xpath, xmlDoc, null, XPathResult.ANY_TYPE,null);Select all the titlesThe following example selects all the title nodes:Example

/bookstore/book/titleSelect the title of the first bookThe following example selects the title of the first book node under the bookstore element:

Example

/bookstore/book[1]/title

109

Sunil Kumar Sahu,Lecturer RCETSlide110

XML Parser

All modern browsers have a built-in XML parser.An XML parser converts an XML document into an XML DOM object - which can then be manipulated with JavaScript.110Sunil Kumar Sahu,Lecturer RCETSlide111

111

Sunil Kumar Sahu,Lecturer RCETSlide112

112

Sunil Kumar Sahu,Lecturer RCETSlide113

XML Application

XML is a meta-markup language for designing domain-specific markup languages. Each XML-based markup language is called an XML application.Each XML application has its own syntax and vocabulary.113

Sunil Kumar Sahu,Lecturer RCETSlide114

Chemical

Markup LanguageCML was originally developed as an SGML application, and gradually transitioned to XML as the XML standard developed. In its most simplistic form, CML is “HTML plus molecules”, but it has applications far beyond the limited confines of the Web.Molecular documents often contain thousands of different, very detailed objects.For example, a single medium-sized organic molecule may contain hundreds of atoms, each with several bonds.114Sunil Kumar Sahu,Lecturer RCETSlide115

Example

(The water molecule H2O)<?xml version=”1.0”?><CML><MOL TITLE=”Water”><ATOMS><ARRAY BUILTIN=”ELSYM”>H O H</ARRAY></ATOMS><BONDS>

<ARRAY BUILTIN=”ATID1”>1 2</ARRAY><ARRAY BUILTIN=”ATID2”>2 3</ARRAY>

<ARRAY BUILTIN=”ORDER”>1 1</ARRAY>

</BONDS>

</MOL>

</CML>

115

Sunil Kumar Sahu,Lecturer RCETSlide116

Mathematical

Markup LanguageThe Mathematical Markup Language (MathML) is an XML application for mathematical equations. MathML is sufficiently expressive to handle pretty much all forms of math.Channel Definition FormatMicrosoft’s Channel Definition Format (CDF) is an XML application for defining channels. Web sites use channels to upload information to readers who subscribe to the site rather than waiting for them to come and get it. This is alternately called Webcasting or push.

116

Sunil Kumar Sahu,Lecturer RCETSlide117

A CDF document is an XML file, separate from, but linked to an HTML document on the site being pushed.

The channel defined in the CDF document determines which pages are sent to the readers, how the pages are transported, and how often the pages are sent.You can add CDF to your site without changing any of the existing content.117Sunil Kumar Sahu,Lecturer RCETSlide118

Synchronized Multimedia Integration Language

The Synchronized Multimedia Integration Language (SMIL, pronounced “smile”) is a W3C recommended XML application for writing “TV-like” multimedia presentations for the Web. SMIL documents don’t describe the actual multimedia content (that is the video and sound that are played) but rather when and where they are played.118Sunil Kumar Sahu,Lecturer RCETSlide119

A SMIL film festival

<?xml version=”1.0” encoding=”ISO-8859-1”?><!DOCTYPE smil PUBLIC “-//W3C//DTD SMIL 1.0//EN”“http://www.w3.org/TR/REC-smil/SMIL10.dtd”><smil><body><

seq id=”Kubrick”><audio

src

=”beethoven9.mid”/>

<video

src

=”corange.mov”/>

<text

src

=”clockwork.htm”/><audio src=”zarathustra.mid”/><video src=”2001.mov”/>

<text src=”aclarke.htm”/>

</

seq

>

</body>

</

smil

>

119

Sunil Kumar Sahu,Lecturer RCETSlide120

HTML+TIME

HTML+TIME builds on SMIL to support timing for traditional HTML elements and features much closer integration with the HTML on the Web page.Open Software DescriptionOSD defines XML tags that describe software components. The description of a component includes the version of the component, its underlying structure, and its relationships to and dependencies on other components.120Sunil Kumar Sahu,Lecturer RCETSlide121

Scalable Vector Graphics

Vector graphics are superior to the bitmap GIF and JPEG images currently used on the Web for many pictures including flow charts, cartoons, advertisements, and similar images.A vector graphics format for the Web should support a lot of features that don’t make sense on paper like transparency, anti-aliasing, additive color, hypertext, animation, and hooks to enable search engines and audio renderers to extract text from graphics.121Sunil Kumar Sahu,Lecturer RCETSlide122

Vector

Markup LanguageMicrosoft has developed their own XML application for vector graphics called the Vector Markup Language (VML). VML is more finished than SVG, and is already supported by Internet Explorer 5.0 and Microsoft Office 2000. MusicMLThe Connection Factory has created an XML application for sheet music called MusicML.MusicML includes notes, beats, clefs, staffs, rows, rhythms, rests, beams, rows, chords and more.

122Sunil Kumar Sahu,Lecturer RCETSlide123

VoxML

Motorola’s VoxML is an XML application for the spoken word. In particular, it’s intended for those annoying voice mail and automated phone response systems.VoxML enables the same data that’s used on a Web site to be served up via telephone.Human Resources Markup LanguageHuman Resources Markup Language (HRML) is an XML application that provides a simple vocabulary for describing job openings. It defines elements matching the parts of a typical classified want ad such as companies, divisions, recruiters, contact information, terms, experience, and more.

123

Sunil Kumar Sahu,Lecturer RCET