25
WEB TECHNOLOGIES http://www.lectnote.blogspot.com/ 1 Document Type Declarations Document Type Declaration is a statement embedded in XML document whose purpose is to acknowledge the ex istence and location of the Document T ype Definition (DTD). Document Type Definition is a set of rules that defines the structure of an XML document. It tells, what tags we can use in a document, what order they should app ear in, which tags can appear inside other ones, which tags have attribute so on. All document type declaration begins with the string “<!DOCTYPE” <!DOCTYPE…………>  The document type declaration can have an internal and/or an external component known as the internal subset (Internal DTD) or an External subset (External DTD) respectively. Internal Subset ( Internal DTD) The internal subset, if present, is delimited by angle brackets as shown here <!DOCTYPE…..[ <!—Internal Subset--> ]> Eg: <<!DOCTYPE apples[ <!ELEMENT apples(#PCDATA)> ]> <apples>12</apples> #PCDATA :- Parsed Character Data, which ex plicitly means that the text that not contain markups, just simple character data. External Subset (External DTD) The external subset; if present consists of a reference to an external entity following the DOCTYPE keyword. apples.dtd <!ELEMENT apples (#PCDATA)> apples.xml <!DOCTYPE SYSTEM “apples.dtd”> <apples>12</apples> A document with both an external and an internal document type declaration is shown here. apples.dtd <!ELEMENT apples(#PCDATA)> apples.xml <!DOCTYPE SYSTEM “apples.dtd” [

WT Module2

Embed Size (px)

Citation preview

Page 1: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 1/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

1

Document Type Declarations

Document Type Declaration is a statement embedded in XML document whose purposeis to acknowledge the existence and location of the Document Type Definition (DTD).

Document Type Definition is a set of rules that defines the structure of an XMLdocument.

It tells, what tags we can use in a document, what order they should appear in, which tags

can appear inside other ones, which tags have attribute so on.

All document type declaration begins with the string “<!DOCTYPE”

<!DOCTYPE…………> The document type declaration can have an internal and/or an external component known

as the internal subset (Internal DTD) or an External subset (External DTD) respectively.

Internal Subset ( Internal DTD)

The internal subset, if present, is delimited by angle brackets as shown here

<!DOCTYPE…..[<!—Internal Subset-->

]>Eg:

<<!DOCTYPE apples[

<!ELEMENT apples(#PCDATA)>]>

<apples>12</apples>

#PCDATA :- Parsed Character Data, which explicitly means that the text that not contain

markups, just simple character data.

External Subset (External DTD)

The external subset; if present consists of a reference to an external entity following the

DOCTYPE keyword.apples.dtd

<!ELEMENT apples (#PCDATA)>

apples.xml

<!DOCTYPE SYSTEM “apples.dtd”>

<apples>12</apples>

A document with both an external and an internal document type declaration is shown

here.

apples.dtd<!ELEMENT apples(#PCDATA)>

apples.xml<!DOCTYPE SYSTEM “apples.dtd” [

Page 2: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 2/25

Page 3: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 3/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

3

<!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)>

<!ELEMENT heading (#PCDATA)>

<!ELEMENT body (#PCDATA)>]>

Document Type Declaration is a construct in which any element type declaration,attribute list declaration, entities declaration and notation declarations are housed.

Element Type Declarations

Element type declarations allow an xml application to constrain the element that can

occur in the document and to specify the order in which can occur.To validate an XML

document ,a validating parser needs to know three things about each element1)  What the element type is named

2)  What elements of that type can contain(content model)

3)  What attributes an element of that type has associated

Both the element type name and its content model are declared together in what is knownas Element Type declaration 

Element Type declaration must start with the string “<!ELEMENT “ followed by thename and content specification

Every element has certain allowed content. There are four general types of contentspecification

1) EMPTY content may not have content

Eg: <!ELEMENT stock EMPTY>2) ANY content may have any combination of elements in any order 

Eg: <!ELEMENT stock ANY>3) Mixed content may have character data or mix of character data and sub

elements

Eg: <!ELEMENT to(#PCDATA)>

4) Element Content May have only sub elements in element content

specifications.Eg: <!ELEMENT mail(to, from, heading, body)>

Element Type Content Models

1)  A sequence of elements one after another 

<!ELEMENT person(name, address, telephone)>This declaration says that “a person element consist of a name element, an address

element and a telephone element in exactly that order.<!--valid person element-->

<person>

<name>……..<address>……

<telephone>…..

Page 4: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 4/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

4

</person>

<!--Invalid person element-->

<person><address>……

<telephone>…..</person>

In above example element <name> is missing.2)  A selection from a list of elements , only one allowed

<!ELEMENT fruit(apples|orange|banana)>

This declaration says “a fruit element consists of an apple element, an orangeelement or a banana element”.

<!—valid fruit element-->

<fruit><apple>…….

</fruit>

<!- -Invalid fruit element- ->

<fruit>

<apple>…….<orange>….

</fruit>

3)  An element occurring once or not at all

<!ELEMENT person(name,address,telephone?)>This declaration says “a person element consists of a name element followed by

an address element, optionally followed by a telephone element”.

<!--valid person element--><person>

<name>……..<address>……

</person>

<!--valid person element-->

<person>

<name>……..

<address>……<telephone>…..

</person>

<!--Invalid person element-->

<person><name>……..<address>……

<telephone>…..

<telephone>…..

Page 5: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 5/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

5

</person>

<telephone> can occur only once or not at all

4)  An element occurring zero or more times<!ELEMENT (name,address,telephone*)>

This declaration says “a person element consists of a name element followed byan address element followed by zero or more telephone element”.

<!--valid person element-->

<person>

<name>……..<address>……

</person>

<!--valid person element-->

<person>

<name>……..<address>……

<telephone>…..

<telephone>…..

</person>5)  An element occurring one or more times

<!ELEMENT (name,address,telephone+)>

This declaration says “a person element consists of a name element followed byan address element followed by one or more telephone element”.

<!--Invalid person element-->

<person><name>……..

<address>……</person>

<!--valid person element--><person>

<name>……..

<address>……

<telephone>…..</person>

<!--valid person element--><person>

<name>……..<address>……<telephone>…..

<telephone>…..

</person>

Page 6: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 6/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

6

6)  An element containing any other element<!ELEMENT person ANY>

This declaration says,”a person element consists of any combination of elements

in any order. It can also contain character data any where”.7)  Character Data: The term character data describes the content of an xml document

that occurs outside any markup (with exception of CDATA sections).In the element type content models, the keyword “#PCDATA” denotes character 

data.Eg:<!ELEMENT para(#PCDATA|quotation)>

<!ELEMENT quotation(#PCDATA)>

If the content model includes the #PCDATA, the element type declaration is saidto have mixed content.

If the content model consists of purely of element type names the element is said

to have element content.

Occurrence Indicator Description

? Optional (0 or 1 times)

* Optional & repeatable (0 or more times)

+ Required & repeatable (1 or more times)

Element Type Declaration Interpretation

<!ELEMENT stock EMPTY>  An element of type stock does not contain

anything ex: <stock/>

<!ELEMENTcontact(name,address,phone)> An element of type contact contains 3 subelements name, address and phone exactly in

that order.

Ex:<contact> <name>aaa</name>

<address>SJCET,pala</address>

<phone>239301</phone></contact>

<!ELEMENT

contact(name,address?,phone)>

An element of type contact contains name

element followed by an optional address element and phone .address can occur once or 

not at all  Ex:<contact> 

<name>aaa</name><phone>239301</phone></contact> 

<!ELEMENT

fruit(apple|orange)>

An element of type fruit contains either a single

apple element or a single orange element. A

Page 7: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 7/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

7

selection from a list of element, only one

allowed

<fruit><apple>---</apple></fruit>

<!ELEMENTfruit(apple|orange)+>

An element of type fruit contains one or more 

sub elements that are either apple element or orange element

Ex1:<fruit><apple>---/apple>

<apple>---</apple>

<orange>--</orange></fruit>

Ex2:<fruit>

<orange>--</orange></fruit>

<!ELEMENT

fruit(apple|orange)*>

An element of type fruit contains zero or more 

sub elements that are either apple element or 

orange elementEx1:<fruit><apple>---/apple>

<orange>---</orange><fruit>

Ex2:<fruit></fruit>

<!ELEMENT

para(#PCDATA|list)*>

An element of type para contains a mixture of character data and list elements in any order. 

Ex1:<para>Here is my list<list>---</list></para>

Ex2:<para>aaa,bbb,ccc</para>

Ex3:<para><list>---</list></para>

<!ELEMENT

invoice(from,to,item+)>

An invoice element consists of a from elementfollowed by to element followed by one or 

more item element

<!ELEMENT

invoice(from,to*,item+)>

An invoice element consists of a from element

followed by zero or more to element followed

 by one or more item element

<!ELEMENT invoice ANY>

An invoice element consists of any combination

of elements or character data, in any order .

Attribute List Declarations

Attribute list declarations serve to specify the name, type and optionally the default value

of the attribute associate with an element. There are ten different attribute types exist.

They are String, Enumerated, ID, IDREF,IDREFS, ENTITY, ENTITIES, NMTOKEN,

 NMTOKENS,NOTATION.

Page 8: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 8/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

8

• STRING ATTRIBUTESThe simplest type of attribute is the CDATA or string attribute. CDATA attribute

values can be any string of characters. For example

<!ATTLIST product name CDATA …… > An element of type product has an attribute called name whose values can be

any string of characters except <,>,& . String attribute can contain an arbitrary collectioncharacters of any length as long as any occurrence of “<” or “&” is escaped with entity

references.

Sample:<product name=”Acme”> or  <product name=”Profit &amp;Loss”>

• ENUMERATED ATTRIBUTESA list of permissible values can be supplied using an enumerated type attributes.

An enumerated attribute is one that can take on one of a fixed set of values supplied as

 part of its declaration.

Ex:<!ATTLIST product name CDATA ……. Color(red|green) ………>

An element of type product has two attributes known as name and color. The name

attribute can have any string of characters except <,>,&.color attribute must be either the

string “red” or “green” .

<product name=”acme” color=”red”>Remember the enumerated attribute elements are case sensitive.

<!ATTLIST apple quality(GOOD|BAD|INDIFFERENT) .....>The quality attribute is declared to have three permissible values “GOOD”, ”BAD” and

“INDIFFERENT” .here is a valid apple element

<apple quality=”GOOD”> and following is an invalid apple element<apple quality=”good”>

• ID/IDREF/IDREFSThere three attribute types are treated as together as they are strongly interrelated.

Any ID attributes occurring in an XML document must be unique in order for the

document to be valid. Attributes of type  ID thus provide a handy way of a name to anelement to uniquely identify it . ID’s must begin with a letter, a “_” ,or a “:” character .Inthis example a UniqueName attribute is attached to hello element :  

<!ATTLIST hello UniqueName ID …….>

the sample element might look like this<hello UniqueName =”P1234”>

An IDREF attribute assigned values in a valid XML document must match the valueassigned to an ID attribute somewhere in the document.

<!ATTLIST bar Reference IDREF ….>

Page 9: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 9/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

9

Here is an example of bar element using its IDREF attribute to point to the hello elementof the last example.

<bar Reference=”P1234”>

IDREFS is a variation on IDREF in which an attribute is allowed to contain multiple

referenced IDs .So given this declaration:<!ATTLIST bar References IDREFS ……>

 bar element might look like this:<bar References=”P1234Q5678”>thus the value IDREFS attribute may contain multiple IDREF values separated by White

Spaces.

• ENTITY/ENTITIESAttribute of type ENTITY or ENTITIES are treated together as they are strongly

related. An Attribute of type ENTITY must have a value corresponding to the name of an

unparsed entity declared somewhere in the Document Type Declaration. In this examplean external data entity, bob, is declared and the salutation attribute of the letter element is

declared to be type ENTITY.

<!ENTITY bob system “bob.gif” NDATA gif>

<!ATTLIST letter salutation ENTITY …>

The letter element might look like this: <letter salutation=”bob”>Like IDREFS above, ENTITIES is a variation on ENTITY that allows an attribute to

contain one or more entity names in its value.

• NMTOKEN /NMTOKENSAttribute of type NMTOKEN or NMTOKENS are treated together as they are strongly

related. An NMTOKEN attribute is restricted to contain characters allowed in a name:

any combination of letters, digits and some punctuation characters “.”, ”-”, ”_” and“:”.Note that this list does not contain any white space characters.

An NMTOKENS attribute is one that can contain one or more NMTOKEN separated by

white spaces.<!ATTLIST product code NMTOKEN ….>

Product elements might look look like this:

<product code=”Alpha-123”> or<product code=”333”>Here is an example of invalid NMTOKEN attribute 

<product code=”A 123”>

• NOTATION

An attribute list declaration of type NOTATION must specify one or more notationsdeclared somewhere in the Document Type Declaration. Its value is constrained to

match one of those notations.In this example, a notation EDIFACT is declared and the format attribute of the invoice

element is declared to be of type NOTATION.

<!NOTATION EDIFACT SYSTEM “EDIFACT Format”>

<!ATTLIST invoice format NOTATION (EDIFACT)>…………………..

Page 10: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 10/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

10

<invoice format=”EDIFACT”>

ATTRIBUTE DEFAULTSAn Attribute list declaration includes information about whether or not a value must be

supplied for it and if not, what the XML processor should do.

There are three different variations:

1)Required --->a value must be specified.2)Implied --->the XML processor tells the application that no value was supplied. The

application can decide what best to do.

3)Fixed --->A value is supplied in the declaration. No value need be supplied in the

document and the XML processor will pass the specified fixed value through thedocument. If a value is supplied in the document, it must exactly match the fixed value.

#REQUIRED -The attribute must have an explicitly specified value on everyoccurrence of the element in the document.

<!ATTLIST product name CDATA #REQUIRED>

An element of type product has an attribute called name whose value can be any string of chars except <,>,&.The value must be supplied when it is used in the document.

<product name=”Acmepc”>

In this example the type attribute of the fruit element is declared to be required.

<!DOCTYPE fruit[ <!ELEMENT fruit EMPTY>

<!ATTLIST fruit type CDATA #REQUIRED>]><fruit type=”apple”/>

A validating XML parser would thus reject the following document

.<!DOCTYPE fruit[<!ELEMENT fruit EMPTY><!ATTLIST fruit type CDATA #REQUIRED>]>

<fruit />

#IMPLIED -These are attributes that can be left unspecified if desired. The XML

 processor passes the fact that the attribute was unspecified through out the XML

application, which can then choose what best to do.Valid document.

<!DOCTYPE fruit[<!ELEMENT fruit EMPTY>

<!ATTLIST fruit type CDATA #IMPLIED>]><fruit />

<!ATTLIST product color(red|green) #IMPLIED>

An element of type product has an attribute called color. Color attribute must be either 

string “red” or “green”. If the value is not supplied, leave it up to the XML application to

decide what to do.

<product color=”red”>…………</product> or <product> is also valid.

Page 11: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 11/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

11

#FIXED – An attribute declaration may specify that an attribute has a fixed value. In this

case attribute is not required, but if it occurs it must have a specific value. 

<!ATTLIST product name CDATA #FIXED “Acmepc”>An element of type product has an attribute called name having a fixed value Acmepc.

Any other value is an Error.<product name=”Acmepc”>

DISPLAYING XML DATA IN HTML BROWSER AS HTML

TABLES

• Microsoft Internet Explorer contains built in support for XML in the form of an XML  parser known as msxml. Microsoft has an overall strategy for making structured

information available to HTML browser in the form of  Data Source Object.

• Microsoft has added support for XML via XMLDSO applet which exposes XML datasource in the same as the traditional databases. 

• Getting XML elements into HTML elements with XMLDSO consists of following

stage a.  Create the HTML page and include an applet element to load the

XMLDSO object that specifies the name of the XML document to load.b.  Create the HTML elements that are data aware .Use datasrc attribute of 

table to connect to the table and applet with id xmldso.

c.  Use the datafld attribute to specify the name of the data field each cell will

contain. 

• The applet element in the HTML document looks like this:

<applet code=com.ms.xml.dso.XMLDSO.class width=100% height=1 id=xmldso >

<PARAM NAME="url" VALUE="catalog.xml">

</applet>

The com.ms.xml.dso package contains an applet called XMLDSO that can be used as

an XML data provider in conjunction with the data binding features of InternetExplorer 4.0. for binding XML data to HTML element on the page .

The APPLET parameters are as follows:

URL  A relative or absolute URL that points to an XML file. Typically, this data

comes from the same place as the HTML page containing the APPLET tag.

inline

XML 

The XML can be placed inside the APPLET so that you don't have to make

another HTTP request to get the data.

id Id attribute give a unique name to the Applet.

param Param element is used to specify the name of the XML document to be

 processed

•  Next we need to create an HTML table to lay out the information .We can write thestart of the table element to fit our data which is to be displayed.

Page 12: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 12/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

12

<table datasrc="#xmldso" border="1" align="center"><thead>

<th>Name</th>

<th>Capacity</th><th>Price</th>

</thead>

This is a simple HTML start tag with table heading information.The datasrc tag connect the table with the applet with the id xmldso.

• The body of the table should look like this<tr> <td><div datafld="NAME"></td>

<td><div datafld="CAPACITY"></td>

<td><div datafld="PRICE"></td>

</tr>

This table row is declared to contain three table cells .The datafld attribute is used tospecify the name of the data field each cell will contain.

• These fields are XML elements namely name,capacity,and price element from theXML source document.The XMLDSO applet works with the browser to expand this

table to as many rows as required to display all the information in the XMLdocument.The XML document is given below.

//catalog.xml

<?xml version="1.0"?>

<PCS><PC>

<NAME>Zenith</NAME>

<CAPACITY>100</CAPACITY><PRICE>20000</PRICE>

</PC>

<PC><NAME>DELL</NAME>

<CAPACITY>200</CAPACITY>

<PRICE>40000</PRICE>

</PC>

<PC><NAME>Acer</NAME>

<CAPACITY>300</CAPACITY><PRICE>35000</PRICE>

</PC>

</PCS>

The full HTML document appears like this:

Page 13: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 13/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

13

//catalog.html

<html><body>

<applet code=com.ms.xml.dso.XMLDSO.class width=100% height=1 id=xmldso ><PARAM NAME="url" VALUE="catalog.xml">

</applet><table datasrc="#xmldso" border="1" align="center" width=200>

<thead>

<th>Name</th><th>Capacity</th><th>Price</th></thead>

<tr> <td><div datafld="NAME"></td>

<td><div datafld="CAPACITY"></td><td><div datafld="PRICE"></td>

</tr>

</table></body>

</html>

//output

Name Capacity Price

Zenith 100 20000

DELL 200 40000

Acer 300 35000

ALTERNATE METHOD FOR DISPLAY IN BROWSER WITHOUT XMLDSOWe can use the <xml> tag with id and src as attribute instead of applet tag.Id takes the

root element’s value and src is the xml document it points to.We can get the same outputusing the following code.

 //catalog1.html 

<html><body>

<xml id="PCS" src="catalog.xml">

</xml>

<table datasrc="#PCS" border="1" align="center"><thead><th>Name</th><th>Capacity</th><th>Price</th></thead>

<tr><td><div datafld="NAME"></td><td><div datafld="CAPACITY"></td><td><div datafld="PRICE"></td>

</tr>

</table></body></html>

STORING XML DATA IN HTML BROWSER 

Page 14: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 14/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

14

XMLDSO produces XML data as a part of the HTML page, rather than accessing itexternally .This can be done by embedding the source XML within applet element .The

applet may be allowed to access the HTML page. To allow this access, set the

MAYSCRIPT attribute to TRUE .The HTML document looks like this://catalog1.html

<html><body>

<p>XML catalog displayed in an HTML table</p><applet code=com.ms.xml.dso.XMLDSO.class width=100% height=1 id=xmldsomayscript=TRUE>

<!- -XML stored in an HTML page as part of the applet element -->

<PCS>

<PC><NAME>Zenith</NAME>

<CAPACITY>100</CAPACITY>

<PRICE>20000</PRICE></PC>

<PC>

<NAME>DELL</NAME><CAPACITY>200</CAPACITY>

<PRICE>40000</PRICE>

</PC>

<PC><NAME>Acer</NAME>

<CAPACITY>300</CAPACITY>

<PRICE>35000</PRICE>

</PC></PCS></applet><! --table declaration starts here-->

<table datasrc="#xmldso" border="1" align="center" width=200>

<thead>

<th>Name</th><th>Capacity</th><th>Price</th></thead>

<tr> <td><div datafld="NAME"></td>

<td><div datafld="CAPACITY"></td><td><div datafld="PRICE"></td>

</tr></table></body></html>

NB: In the same way we can store XML data within an HTML document using XML(<xml>add xml code here</xml>)tag.there is no need of applet tag use the root element 

name instead of  xmldso as datasrc in table tag

VIEWING XML DATA ONE RECORD AT A TIME USING XMLDSO

Step1 :use the same catalog.xml

Step2:create the cat.html file with the following content

Page 15: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 15/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

15

<html><body>

<applet code=com.ms.xml.dso.XMLDSO.class width=70% height=25 id=xmldso

MAYSCRIPT=true><PARAM NAME="url" VALUE="catalog.xml">

</applet><table border="1" align="center" width=200>

<tr> <td><b>Name</b></td><td><div datasrc="#xmldso" datafld="NAME"></td></tr>

<tr><td><b>Capacity</b></td>

<td><div datasrc="#xmldso" datafld="CAPACITY"></td></tr><tr><td><b>Price</b></td>

<td><div datasrc="#xmldso" datafld="PRICE"></td></tr>

</table><p align=center>

<input type=button value="Previous"

onclick='xmldso.recordset.moveprevious()'><input type=button value="Next"

onclick='xmldso.recordset.movenext()'>

<input type=button value="First"

onclick='xmldso.recordset.movefirst()'><input type=button value="Last"

onclick='xmldso.recordset.movelast()'>

</p></body></html>

//output

We had created the XML record with Previous ,Next ,First ,Last buttons allowing the

user to navigate through the XML record one at a time .The individual cells rather thanthe table specify the data source as xmldso.

This signals to the browser that it should not process the entire document in one go,but

rather process it one record at atime,keeping track of the current position.

Page 16: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 16/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

16

ADDING EDITABLE FIELDS UP TO A LIVE UPDATING TABLE

Step1:use the same catalog.xml

Step2: create cat2.html with the following code

<html><body><applet code=com.ms.xml.dso.XMLDSO.class width=70% height=25 id=xmldso

MAYSCRIPT=true><PARAM NAME="url" VALUE="catalog.xml">

</applet><table border="1" align="center" width=200>

<tr> <td><b>Name</b></td> <td><input type=text size=50 datasrc="#xmldso"

datafld="NAME"></td></tr><tr> <td><b>Capacity</b></td> <td><input type=text size=50 datasrc="#xmldso"

datafld="CAPACITY"></td></tr>

<tr> <td><b>Price</b></td> <td><input type=text size=50 datasrc="#xmldso"datafld="PRICE"></td></tr></table>

<script>

function AddRecord(){ xmldso.recordset.AddNew();

UpdateRecord(); }

function UpdateRecord(){ xmldso.recordset("name") = document.all.item("name").value;

xmldso.recordset("capacity") = document.all.item("capacity").value;

xmldso.recordset("price") = document.all.item("price").value;

}function RemoveRecord()

{ xmldso.recordset.Delete(); }

function MoveToRecord(i)

{ xmldso.recordset.MoveFirst();while (i > 0) {

xmldso.recordset.MoveNext();i = i - 1;

} }

function selectCell(){ var row = window.event.srcElement;

while (row.tagName != "TR")

row = row.parentElement;var table = row;

while (table.tagName != "TABLE")

table = table.parentElement;var rows = table.rows;var result = -1;

for (i=0; i < rows.length; i++) {color = "";if (row == rows(i)) {

color = "pink";

result = i-1;

Page 17: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 17/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

17

}var cells = rows(i).cells;

for (j = 0; j < cells.length; j++) {

var e = cells(j);e.style.backgroundColor = color;

} }return result; }

</script><P align=center>

<input type=button value="Add Record" onclick='AddRecord();'>

<input type=button value="Delete Record" onclick='RemoveRecord();'></p>

<table datasrc="#xmldso" border="1" align="center" width=200

onClick='MoveToRecord(selectCell())'><thead>

<th>Name</th><th>Capacity</th><th>Price</th>

</thead><tr> <td><div datafld="NAME"></td>

<td><div datafld="CAPACITY"></td>

<td><div datafld="PRICE"></td>

</tr></table></body></html>

//output

DISPLAY HIERARCHIAL XML AS NESTED HTML TABLES

Page 18: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 18/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

18

Step1: create catalog1.xml

<?xml version="1.0"?>

<PCS><PC><NAME>Zenith</NAME>

<CAPACITY><RAM>10</RAM><DISK>200</DISK> </CAPACITY>

<PRICE>20000</PRICE></PC><PC><NAME>DELL</NAME>

<CAPACITY><RAM>20</RAM>

<DISK>300</DISK></CAPACITY>

<PRICE>40000</PRICE> </PC>

</PCS>

Step2: create the cat3.html with the following content <html><body>

<applet code=com.ms.xml.dso.XMLDSO.class width=70% height=25 id=xmldso

MAYSCRIPT=true><PARAM NAME="url" VALUE="catalog1.xml">

</applet>

<table datasrc="#xmldso" border="1" align="center" width=300>

<thead><th>Name</th><th>Capacity</th><th>Price</th></thead><tr><td><div datafld="NAME"></td>

<td><table datasrc="#xmldso" datafld="CAPACITY " border="1" align="center" 

width=150> <thead><th>RAM</th><th>DISK</th></thead>

<TR><TD><div datafld="RAM"></td><TD><div datafld="DISK"></td>

</TR></table></td><td><div datafld="PRICE"></td>

</tr></table></body></html>

//output

Page 19: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 19/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

19

EXTENSIBLE STYLE SHEET LANGUAGE (XSL)

XSL a transformation language that enables the conversion of XML into grammar andstructure suitable for display in the browser .XSL allows direct browsing of XML file

using explorer or any browser. The basic tags that are used in the XSL is given below.

• xsl:stylesheet :This is the first element in the style sheet .In this element we canspecify the Namespace for style sheet.

XML Namespace is a collection of names identified by a URI (Uniform Resource

Identifier) or a URL (Uniform Resource Locater) reference which are used in the XML

document as element type and attribute names .

By using the namespace, developers can qualify element names uniquely on the web

and thus avoid conflicts between element that have same name. Imporatant namespacesare given below.

a)  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'

This is the official standard transformation namespace used as a part of the W3C

recommendation.[W3C is World Wide Web Consortium , which is a forum for information, commerce ,communication and collective understanding] .It is not

supported by IE5.0

 b)  xmlns:xsl='http://www.w3.org/TR/WD-xslThis is the namespace used for style sheet processed by IE5.

The important xsl:stylesheet attributes are as follows:

1)id style sheet unique identifier 2) xmlns:xsl Declares the namespace for the current specification. This is a fixed

attribute with the value 'http://www.w3.org/1999/XSL/Transform'

• xsl:template : Template is a structured container that manages the way a source tree

or a portion of the source tree is transformed. when you build a style sheet ,you will build a series of template that match elements you would like to attach some styles to.

xsl:template defines a set of riles for transforming nodes in a source document into aresult tree .This is handled with match attributes. The important xsl:template attributes

are as follows: 

1)mode  Identifies the processing mode and matches it against an apply-templateelement that has matching template value.

2)Name Give a name to the template so that it can be accessed.

3)match  Identifies the template to be processed.

• xsl:apply-template : This element tells the processor to process a named template

that has been defined using xsl:template element. Possible attributes are given below: 1) select  Identify the node to be processed. If this attribute is not specified, then processor will process the template of the current node in the order of their appearance

in the root document

2)mode Identify the processing node and selects only those template elements thathave a matching node value.

Page 20: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 20/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

20

• xsl:for-each : This element locates the set of elements in the XML data and repeats a portion of the template for each one .Possible attributes are 

1)select  Identify the node to be processed.

2)xml-spaceindicates whether or not white space present.

• xsl:value-of : within <xsl:for-each> element we can further drill down to selectchildren.<xsl:value-of> element specifies a specific child and then insert the text

content of that child into that template using select attribute .select attribute specifies

the node to be processed. 

CONVERTING XML INTO HTML WITH XSL

An XSL style sheet are themselves XML documents. The XSL is based on set of rules

that trigger when specified elements are encountered in an XML document. Every

XML page should contain an XSL file to display it in an explorer. Example 1 :To display a Welcome Message

Step1: create a hello.xml file with the following content<?xml version="1.0"?>

<!---Internal Document type Definition-->

<!DOCTYPE hello[

<!ELEMENT hello (msg)><!ELEMENT msg (#PCDATA)>]>

<!---Style sheet reference-->

<?xml:stylesheet href="hello.xsl" type="text/xsl"?><!--standard XML code-->

<hello>

<msg>Welcome to XML world</msg>

</hello>Step2:create the hello.xsl file

<xsl:stylesheet version="1.0"

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'></xsl:stylesheet>

Step3: browser the hello.xml file on the browser you will get the output.

The DTD part can also be neglected for simple file like this the XSL will take care of the document.

 Example 2 :To display different Message //hello1.xml<?xml version="1.0"?>

<?xml:stylesheet href="hello1.xsl" type="text/xsl"?><hello> <wel>welcome to XML</wel><xm><xm1>XML is eXtensible Markup Language</xm1>

<xm2>

<sg1>SGML is Standard Generalized Markup Language</sg1><sg2>XML is a subset of SGML</sg2> </xm2></xm></hello>

Page 21: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 21/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

21

//hello1.xsl<xsl:stylesheet version="1.0"

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="hello"><html><body><table>

<tr><td align="center"><h1><xsl:value-of select="wel"/></h1></td></tr>

<xsl:for-each select="xm"><tr><td>

<h2><xsl:value-of select="xm1"/></h2></td></tr>

<xsl:for-each select="xm2"><tr><td>

<h3><xsl:value-of select="sg1"/></h3></td></tr>

<tr><td><h3><xsl:value-of select="sg2"/></h3></td></tr>

</xsl:for-each></xsl:for-each>

</table></body></html></xsl:template>

</xsl:stylesheet>

 Example 3:

Page 22: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 22/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

22

//Email.xml<?xml version="1.0"?>

<!-- This is a sample email data file -->

<?xml:stylesheet href="email.xsl" type="text/xsl"?><mail>

<Recipient>[email protected]</Recipient><Sender>[email protected]</Sender>

<Date>Mon, 21 Apr 1997 09:27:55 +0200</Date><Subject>XML literature</Subject>

<Textbody>

<sal>Hello Mrs Sarju,</sal><content>Please read Jon Bosak's introductory text

"SGML, Java and the Future of the Web"</content>

<thanks> Best wishes, </thanks><name>Krishnalal G </name>

</Textbody>

</mail>//Email.xsl 

<!--Since Style Sheet is an XML itself, the file begins with xml declarationthe <xsl:stylesheet> element indicates that this document is a style sheet file and provides

the location for declaring XSL namespace.

Also wrap the entire template with <xsl:template match="/"> to indicate that this

template corresponds to the root(/)of the XML document --><xsl:stylesheet version = '1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">

<HTML><BODY><TABLE BORDER="0">

<TR><TD>MAIL DETAILS</TD> </TR>

<xsl:for-each select="mail">

<TR> <TD><xsl:value-of select="Recipient"/></TD></TR>

<TR> <TD><xsl:value-of select="Sender"/></TD></TR><TR> <TD><xsl:value-of select="Date"/></TD></TR>

<TR><TD><xsl:value-of select="Subject"/></TD></TR>

<TR><TD><xsl:for-each select="Textbody"> 

<xsl:value-of select="sal"/>

<br/><xsl:value-of select="content"/><br/><br/><xsl:value-of select="thanks"/>

<br/><xsl:value-of select="name"/>

</xsl:for-each>

</TD></TR></xsl:for-each></TABLE></BODY></HTML></xsl:template></xsl:stylesheet>

//output

Page 23: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 23/25

Page 24: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 24/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

24

<!ELEMENT BOOK (BOOKNAME,AUTHORNAME,ISBN,PUBLISHER,PAGES,PRICES)>

<!ATTLIST BOOK BESTSELLER (YES|NO) #REQUIRED>

<!ELEMENT BOOKNAME (#PCDATA)><!ELEMENT AUTHORNAME (#PCDATA)>

<!ELEMENT ISBN (#PCDATA)><!ELEMENT PUBLISHER (#PCDATA)>

<!ELEMENT PAGES (#PCDATA)><!ELEMENT PRICE (#PCDATA)>

<!ATTLIST PRICE CURRENCY CDATA #REQUIRED>

]><CATALOGS><CATEGORY TYPE="XML">

<BOOK BESTSELLER="NO">

<BOOKNAME>CLOUDES TO CODE</BOOKNAME><AUTHORNAME>JESSE</AUTHORNAME>

<ISBN>111-S223</ISBN><PUBLISHER>WROX</PUBLISHER>

<PAGES>276</PAGES><PRICE CURRENCY="usd">42.00</PRICE>

</BOOK></CATEGORY>

<CATEGORY TYPE="XML">

<BOOK BESTSELLER="YES"><BOOKNAME>XML IN ACTION</BOOKNAME>

<AUTHORNAME>WILLIAM</AUTHORNAME>

<ISBN>222-S223</ISBN><PUBLISHER>TECHMEDIA</PUBLISHER><PAGES>476</PAGES>

<PRICE CURRENCY="usd">87.00</PRICE>

</BOOK></CATEGORY></CATALOGS>

bcatalog.xsl

<?xml version="1.0"?>

<xsl:stylesheet version = '1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match="/">

<html><body><table border="1">

<tr><th>BOOKNAME</th>

<th>AUTHORNAME</th>

<th>ISBN</th><th>PUBLISHER</th><th>PAGES</th>

<th>PRICE</th></tr> 

<xsl:for-each select="CATALOGS/CATEGORY">

<!--<tr><td colspan="6">

<xsl:apply-templates/> </td>

Page 25: WT Module2

8/8/2019 WT Module2

http://slidepdf.com/reader/full/wt-module2 25/25

WEB TECHNOLOGIES http://www.lectnote.blogspot.com/

25

</tr>--><xsl:for-each select="BOOK">

<tr><td valign="top"><xsl:value-of select="BOOKNAME"/> </td>

<td valign="top"><xsl:value-of select="AUTHORNAME"/> </td><td valign="top"><xsl:value-of select="ISBN"/> </td>

<td valign="top"><xsl:value-of select="PUBLISHER"/> </td><td valign="top"><xsl:value-of select="PAGES"/> </td>

<td valign="top"><xsl:value-of select="PRICE"/> </td></tr>

</xsl:for-each>

</xsl:for-each></table></body></html>

</xsl:template>

</xsl:stylesheet>

//output