You are on page 1of 47

Web Technologies (RT 705)

Sarju S
Lecturer Department of Computer Science and Engineering WWW.lectnote.blogspot.com
Java XML Bean

JSP

EJB
1

Module II
Document Type declarations Creating XML DTDs Element type declaration Attribute List Declaration Attribute types Attribute defaults Displaying XML Data in HTML browser as HTML tables Storing XML data in HTML document Converting XML to HTML with XSL minimalist XSL style sheets XML applications

Document Type Declarations


is a statement embedded in XML document whose purpose is to acknowledge the existence and location of the Document Type Definition (DTD). 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.
3

Document Type Declarations


All document type declaration begins with the string <!DOCTYPE Two types
Internal Subset(Internal DTD) External Subset(External DTD)

Internal Subset(Internal DTD)


Document Type Definitions that are included with in the xml document is called Internal DTD. Syntax
<!DOCTYPE..[ <!Internal Subset--> ]>
5

Internal Subset(Internal DTD)


Eg:
<?xml version=1.0 ?> <!DOCTYPE apples[ <!ELEMENT apples(#PCDATA)> ]> <apples>12</apples>
#PCDATA :- Parsed Character Data, which explicitly means that the text that not contain markups, just simple 6 character data.

Internal Subset(Internal DTD)


<?xml version=1.0?> <!DOCTYPE mail [ <!ELEMENT mail(to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>]> <mail> <to>Rani</to> <from>Ravi</from> <heading>Remainder</heading> <body>About our parents Wedding Anniversary</body> </mail>

Internal Subset(Internal DTD)


The DTD is interpreted as follows: 1) <!DOCTYPE mail - indicates that mail is the root element 2) <!ELEMENT mail - element mail has 4 sub elements 3) <!ELEMENT to - Sub element to will be of type PCDATA 4) PCDATA - Element contain only text data 5) # - # is reserved character indicates that #PCDATA is a reserved word

External Subset(External DTD)


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

External Subset(External DTD)


//mail.xml <?xml version=1.0?> <!DOCTYPE mail SYSTEM mail.dtd> <mail> <to>Rani</to> <from>Ravi</from> <heading>Remainder</heading> <body>About our parents Wedding Anniversary </body> </mail>

10

External Subset(External DTD)


//mail.dtd <?xml version=1.0?> <!ELEMENT mail(to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>]>
11

Internal and External


apples.dtd <!ELEMENT apples(#PCDATA)> apples.xml <!DOCTYPE SYSTEM apples.dtd [ <!ATTLIST apples color CDATA #REQUIRED> ]> <apples color=green>12</apples>
12

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.

13

Element Type Declarations


To validate an XML document ,a validating parser needs to know three things about each element 1) 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
14

Element Type Declarations


Both the element type name and its content model are declared together in what is known as Element Type declaration Element Type declaration must start with the string <!ELEMENT followed by the name and content specification

15

Element Type Declarations


Every element has certain allowed content. There are four general types of content specification 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>
16

Element Type Declarations


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

Element Type Declarations

18

Element Type Declarations

19

Element Type Declarations

20

Element Type Declarations

21

Element Type Declarations

22

Element Type Declarations

23

Element Type Declarations

24

Attribute List Declarations


Attribute list declarations serve to specify the name, type and optionally the default value of the attribute associate with an element.
<!ATTLIST element-name attribute-name attribute-type default-value>

There are ten different attribute types exist. They are


25

Attribute Types
String Enumerated ID, IDREF,IDREFS ENTITY, ENTITIES NMTOKEN,NMTOKENS NOTATION.
26

String Attributes
The 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 >

27

String Attributes
An element of type product has an attribute called name whose values can be any string of characters except <,>,& Sample:<product name=Acme> or <product name=Profit &amp;Loss>

28

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

29

Enumerated Attributes
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>
Note : Remember the enumerated attribute elements are case sensitive.
30

ID/IDREF/IDREFS
ID name to an element to uniquely identify it. must begin with a letter, a _ ,or a : character . Example
<!ATTLIST hello UniqueName ID .> the sample element might look like this <hello UniqueName =P1234>
31

IDREF
Represents the value of an ID attribute of another element. <!ATTLIST book Reference IDREF .> the sample element might look like this <hello UniqueName =P1234> <book Reference=P1234>

32

IDREFS
Represents multiple IDs of elements, separated by whitespace. <!ATTLIST book References IDREFS > book element might look like this: <book References=P1234 Q5678>

33

ENTITY/ENTITIES
The name of an entity (which must be declared in the DTD) <!ENTITY bob system bob.gif NDATA gif> <!ATTLIST letter salutation ENTITY > The letter element might look like this: <letter salutation=bob>

34

NMTOKEN /NMTOKENS
A valid XML name. any combination of letters, digits and some punctuation characters ., -, _ and :. Note that this list does not contain any white space characters.

35

NOTATION
An attribute list declaration of type NOTATION must specify one or more notations declared somewhere in the Document Type Declaration.
<!NOTATION EDIFACT SYSTEM EDIFACT Format> <!ATTLIST invoice format NOTATION (EDIFACT)> <invoice format=EDIFACT>
36

ATTRIBUTE DEFAULTS
#IMPLIED #REQUIRED #FIXED value

37

#IMPLIED
Specifies that there is no default value for this attribute, and that the attribute is optional. Syntax
<!ATTLIST element_name attribute_name CDATA #IMPLIED> Example <!ATTLIST tutorial rating CDATA #IMPLIED>
38

#REQUIRED
The attribute must have an explicitly specified value on every occurrence of the element in the document. Syntax <!ATTLIST element_name attribute_name CDATA #REQUIRED> Example <!ATTLIST tutorial published CDATA 39 #REQUIRED>

#FIXED
The #FIXED keyword specifies that you will provide value, and that's the only value that can be used by users of this DTD. Syntax <!ATTLIST element_name attribute_name CDATA #FIXED> Example <!ATTLIST tutorial language CDATA 40 #FIXED "EN">

XSL
XSL stands for Extensible Styles Language and is a very powerful language for applying styles to XML documents.
formatting language transformation language.

41

XSL
The formatting language allows you to apply styles similar to what CSS does. The transformation language is known as XSLT (XSL Transformations).

42

Basic tags that are used in the XSL


xsl:stylesheet
In this element we can specify the Namespace for style sheet.

xmlns:xsl='http://www.w3.org/TR/WD-xsl

43

Basic tags that are used in the XSL


<xsl:template>
tag allows us to select any node in our XML document and transform its contents. Eg: 1. <xsl:template match="hello"> Eg: 2. <xsl:template match=/">

44

Basic tags that are used in the XSL


<xsl:apply-templates/>

45

Basic tags that are used in the XSL


<xsl:template match="/"> (other content/HTML markup goes here) <xsl:apply-templates/> </xsl:template> <xsl:template match="child"> (other content/XSLT/HTML markup goes here) </xsl:template>
46

Basic tags that are used in the XSL


<xsl:for-each>
tag allows you to loop through multiple nodes that match the selection criteria.

<xsl:value-of>
tag allows you to retrieve the value from a node.

47

You might also like