0% found this document useful (0 votes)
4 views

Web technology

About HTML file
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Web technology

About HTML file
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

UNIT – V

Q: Define XML?

Ans: X M L s ta n d s f o r “ E xten s ib le M a rk up L a n g u a g e” . X M L is a tex t-b a s ed m a rk u p


la n g u a g e . A m a rk u p la n g u a g e is a s e t o f in s tru c tio n s o fte n c a lle d a s ta g s w h ic h c a n b e
a d d ed to te xt f ile s . W h e n th e f ile is p ro c es s e d b y a s u ita b le a p p lic a tio n th e ta g s a re u s e d
to c o n tro l th e s tru c tu re a n d p res e n ta tio n o f d a ta c o nta in ed in th e file . M o s t c o m m o n ly
ta g s a re u s ed b y a p p lic a tio n w h en p res e n tin g d a ta . X M L is n o thin g s p e c ia l, it is ju s t a
p la in te xt. S o ftw a re th a t c a n h a n d le p la in tex t c a n a ls o h a n d le X M L. X M L is a
s o f tw a re/ h a rd w a re in d ep en d e n t to o l f o r c a rryin g in fo rm a tio n .

(O R )

X M L is a m a rk u p la n g u ag e s im ila r to H T M L, b u t w ith o u t p re d e fin ed ta g s to u s e. In s te a d ,


yo u d efin e yo u r o w n ta g s d e s ig n ed s p e c ific a lly f o r yo u r n e ed s . T h is is a p o w e rfu l w a y to
s to re d a ta in a fo rm a t th a t c a n b e s to re d , s e arc h ed , a n d s h a re d .

Q: Brifely explain about XML over HTML?

Ans: X M L is m o re th a n H T M L b ec a u s e, H T M L o n ly d ea ls w ith p res e n ta tio n a n d c a rries n o


in fo rm a tio n a b o u t th e d a ta , w h erea s X M L d ea ls w ith th e re p res e n ta tio n o f d a ta a n d
c a rries in fo rm a tio n a b o u t th e d a ta . In X M L, w e c re a te o u r o w n ta g s a n d a ls o s yn ta x fo r
th o s e tag s th a t c a n le t th e d o c u m en t s tru c tu re fo llo w th e d a ta s tru c tu re. A s w e a re
d e fin in g o u r o w n ta g s a n d th ere a re n o p re d e fin ed ta g s , X M L is d e fin ed to b e
“ s elf-d e s c rip tiv e” . U s in g s c rip tin g la n g u ag es lik e ja va s c rip t w e c a n rea c h to va rio u s
ele m e n ts o f a n x m l p a g e a n d m a k e u s e o f d a ta . W h e n c o m p a re d w ith H T M L , X M L
p ro vid e s a w ay o f s tru c tu rin g th e d a ta a n d s to re d a ta w ith fo c u s o n “ W h a t d a ta is ” ,
w h ere H T M L w a s d es ig n e d to d is p la y d a ta w ith fo c u s o n “ H o w d a ta lo o k s ” .

Q: What are the advantages and uses of XML?

Ans: Advantages of XML:

● Readability: X M L d o c u m en t is p la in te xt a n d h u m a n rea d a b le.


• Hierarchal: X M L d o c u m e n t h a s a tree lik e s tru c tu re w h ic h is en o ug h to e xp res s
c o m p lex d a ta a s s im p le a s p o s s ib le .

• Language Independent: X M L d o c u m e n ts a re la n g u a g e n eu tra l. F o r e xa m p le , a ja va


p ro g ra m c an g en e ra te a n X M L w h ic h c a n b e p ars e d b y a p ro g ra m w ritte n in C + + o r p e rl.

• Platform Independent: X M L file s a re o p e ra tin g s ys tem in d ep en d en t

Uses of XML:

• X M L is u s ed to d es c rib e th e c o n ten ts o f a d o c u m e n t.

• X M L is u s ed in m es s a g in g , w h ere a p p lic a tio n s e xc h a n g e d a ta b etw ee n th em .

• T h e d a ta c a n b e e xtra c ted fro m th e d a ta b a s e , c a n b e p re s erve d w ith o rig in a l


in fo rm a tio n a n d c a n b e u s e d in m o re th a n o n e a p p lic a tio n in d iff eren t w a y

Q: Explain about the features of XML?

Ans:

Features and Advantages of XML

X M L is w id ely u s e d in th e e ra o f w eb d e ve lo p m en t. It is a ls o u s e d to s im p lify d a ta s to ra g e
a n d d a ta s h a rin g . T h e m a in fe atu res o r a d v a n ta g es o f X M L a re g iv en b e lo w .

1) XML separates data from HTML

If yo u n ee d to d is p la y d yn a m ic d a ta in yo u r H T M L d o c u m e n t, it w ill ta k e a lo t o f w o rk to
ed it th e H T M L ea c h tim e the d a ta c h a n g e s . W ith X M L , d a ta c a n b e s to re d in s e p a ra te
X M L file s . T h is w a y yo u c an fo c u s o n u s in g H T M L /C S S f o r d is p la y a n d lay o u t, a n d b e s u re
th a t c ha n g es in th e u n d erlying d a ta w ill n o t req u ire a n y c h an g es to th e H T M L .

2) XML simplifies data sharing

In th e re a l w o rld , c o m p u te r s ys te m s a n d d a ta b a s es c o n ta in d a ta in in c o m p a tib le fo rm a ts .
XM L d a ta is s to red in p la in tex t fo rm a t. T h is p ro vid e s a s o ftw a re - and
h a rd w a re -in d e p e n d e n t w a y o f s to rin g d a ta . T h is m a k es it m u c h ea s ie r to c rea te d a ta th a t
c a n b e s h a re d b y d iffere nt a p p lic a tio n s .

3) XML simplifies data transport


O n e o f th e m o s t tim e-c o n s u m in g c h allen g es fo r d ev elo p ers is to ex c h a n g e d a ta b e tw e en
in c o m p a tib le s ys tem s o v er th e In te rn et. E xc h an g in g d a ta a s X M L g rea tly red uc es th is
c o m p lex ity, s in c e th e d a ta c a n b e rea d b y d iffe ren t in c o m p a tib le a p p lic a tio n s .

4) XML simplifies Platform change

U p g ra d in g to ne w s ys tem s ( h a rd w a re o r s o ftw a re p la tfo rm s ), is a lw a ys tim e c o n s u m in g .


La rg e a m o u n ts o f d a ta m us t b e c o n ve rte d a n d in c o m p a tib le d a ta is o ften lo s t. X M L d a ta
is s to red in tex t fo rm a t. T h is m a k es it e a s ier to ex p a n d o r u p g ra d e to n ew o p e ra tin g
s ys tem s , n ew a p p lic a tio n s , o r n e w b ro w s ers , w ith o u t lo s in g d a ta .

5) XML increases data availability

D iffe ren t a p p lic a tio n s c an a c c es s yo u r d a ta , n o t o nly in H T M L p a g es , b u t a ls o fro m X M L


d a ta s o u rc es . W ith X M L , yo u r d a ta c a n b e a va ila b le to a ll k in d s o f "rea d in g m a c h in es "
(H a n d h e ld c o m p u ters , v o ic e m ac h in es , n e w s fee d s , etc ), a n d m a k e it m o re a v a ila b le fo r
b lin d p eo p le, o r p eo p le w ith o th er d is a b ilitie s .

6) XML can be used to create new internet languages

A lo t o f n e w In tern e t la n g u a g e s a re c rea ted w ith X M L.

H ere a re s o m e e xa m p le s :

o XHTML

o W S D L fo r d e s c rib in g a va ila b le w eb s ervic es

o W A P a n d W M L a s m a rk u p la n g ua g es fo r h a n d h e ld d e vic es

o R S S la n g u a g e s fo r n ew s fee d s

o R D F a n d O W L fo r d es c rib in g re s o u rc e s a n d o n to lo g y

o S M IL fo r d es c rib in g m u ltim ed ia fo r th e w eb

Q: What are the basic building blocks of XML documents?

Ans: XML uses the same building blocks as HTML: tags that define elements,
attributes of those elements, and their values.

XML elements:

E le m e n ts c a n b e d ef in e d a s b u ild in g b lo c k s o f a n X M L. E le m e n ts c a n b e h a ve a s
c o n ta in e rs to h o ld te xt, ele m e n ts , a ttrib u te s , m e d ia o b je c ts o r a ll o f th es e . E a c h X M L
d o c u m en t c o n ta in s o n e o r m o re e lem en ts , th e s c o p e o f w hic h a re e ith e r d elim ited b y s ta rt
a n d e n d ta g s , o r fo r em p ty ele m e n ts , b y a n e m p ty-ele m e n t ta g .

Syntax

< ele m e n t-n a m e attrib u te 1 a ttrib u te2 >


... .c o n ten t
< / elem en t-n a m e>

w h ere,

● ele m e n t-n a m e is th e n a m e o f th e elem en t. T h e n a m e its c a s e in th e s ta rt a n d e n d


ta g s m u s t m a tc h .
● a ttrib u te1 , a ttrib u te 2 a re a ttrib u tes o f th e elem en t s e p a ra te d b y w h ite s p a c es . A n
attrib u te d e fin e s a p ro p erty o f th e elem e nt. It a s s o c ia te s a n a m e w ith a v alu e ,
w h ic h is a s trin g o f c h ara c te rs . A n attrib u te is w ritten a s −
n a m e = "v a lu e "

n a m e is fo llo w ed b y a n = s ig n a n d a s trin g v alu e in s id e d o u b le(" ") o r s in g le (' ') q u o tes .

Empty Element

< n a m e a ttrib u te1 a ttrib ute 2 .. ./>

F o llo w in g is a n e xa m p le o f a n X M L d o c u m e nt u s in g va rio u s X M L elem en t −

< ? x m l ve rs io n = "1 .0 "? >


< c o n ta c t-in fo >
< a d d res s c ate g o ry = "re s id en c e">
< n am e > T a n m a y P a til< / n a m e>
< c o m p a ny > T u to ria ls P o in t< /c o m p a n y>
< p h o n e > (0 1 1 ) 1 2 3 -4 5 6 7 < / p h o n e >
< / a d d re s s >
< / c o nta c t-in fo >

XML Elements Rules

● A n elem en t n a m e c a n c o n ta in a n y a lp h a n u m eric c h a ra c ters . Th e o n ly p u n c tu a tio n


m a rk a llo w e d in n a m es a re th e h yp h e n (-), u n d er-s c o re (_ ) a n d p erio d (.).
● N a m e s are c a s e s en s itiv e. F o r ex a m p le, A d d re s s , a d d re s s , an d A D D R E S S a re
d iffe re n t n a m es .
● S ta rt a n d en d ta g s o f a n e lem en t m u s t b e id e n tic a l.
XML Attribute:

X M L ele m e n ts c a n h a ve a ttrib u tes , ju s t lik e H T M L. A ttrib u tes p ro vid e a d d itio n a l


in fo rm a tio n a b o u t a n ele m e n t. A ttrib u te s a re k n o w n a s “ n am e -va lu e p a irs ” a n d a re
c o n ta in e d w ith in th e o p en in g ta g o f a n e lem en t. A ttrib u te v a lu es m u s t a lw a ys b e q u o ted .
E ith er s in g le o r d o u b le q u o tes c a n b e u s e d . F o r a p ers o n ’ s g e n d e r, th e p e rs o n elem en t
c a n b e w ritte n lik e th is :

< p e rs o n g e n d e r= ” m a le” >

OR

< p e rs o n g e n d e r= ’ m a le’ >

In fo rm a tio n c o n ta in e d in a n a ttrib u te is g en era lly c o n s id ered m e ta d a ta : th a t is ,


in fo rm a tio n ab o u t th e d a ta in th e e lem en t, a s o p p o s e d to th e d a ta its elf. A n e le m e n t c a n
h a ve o n e o r m o re th a n o n e a ttrib u tes .

Rules:

1 . A ttrib u te s c a n n o t h a v e c o n ta in m u ltip le v a lu es .
2 . A ttrib u te s c a n n o t c o n ta in tree s tru c tu re.
3 . A ttrib u te s a re n o t e a s ily ex p a n d a b le .

Q: Write about XML document?

Ans: A n X M L d o c u m en t is a b a s ic u n it o f X M L in fo rm a tio n c o m p o s ed o f e le m en ts a n d
o th e r m a rk u p in a n o rd erly p a c k a g e . A n X M L d o c u m e n t c a n c o n ta in s w id e va riety o f d a ta .
F o r ex a m p le, d a ta b a s e o f n u m b e rs , n u m b e rs rep re s en tin g m o lec u lar s tru c tu re o r a
m a th e m a tic a l eq u a tio n .

Example:

< ? x m l ve rs io n = "1 .0 "? >


< w o n d er>
< n a m e > H a n g in g g a rd en s o f B a b ylo n < /n a m e>
< lo c a tio n> B a b ylo n , Ira w < / lo c a tio n >
< h eig h t u n its = ” f eet” > 1 0 7 < / h eig h t>
< / w o n d e r>

T h e firs t lin e o f th e X M L d o c u m e n t < ? X M L v ers io n = ” 1 .0 ” ? > is th e X M L d ec la ra tio n ,


w h ic h s p ec if y th e v ers io n o f X M L yo u a re u s in g . A ll X M L d o c u m e n ts c a n o p tio n a lly b e g in
w ith a n X M L d ec lara tio n .

T h e n e xt lin e < w o n d er> d efin e s th e firs t e le m e n t o f th e d o c u m e n t an d is c a lled th e ro o t


ele m e n t. In a n X M L d o c u m en t, th ere c a n b e o n ly o n e ro o t e lem en t. T h e n ex t th ree lin es
a re c a lled c h ild elem e nts , a n d th ey d es c rib e th e ro o t elem e nt in m o re d eta il. T h e la s t c h ild
ele m e n t h e ig h t c o n ta in s a n a ttrib u te c alled u n its w h ic h is b e in g u s ed to s to re th e s p e c ific
u n its o f th e h eig h t m ea s u rem en t. A ttrib u te s a re u s ed to in c lu d e a d d itio n a l in fo rm a tio n to
th e e lem en t, w ith o u t a d d in g te xt to th e e le m e n t its e lf. F in a lly, th e X M L d o c u m en t e n d
w ith th e c lo s in g ta g o f th e ro o t e lem en t< / w o n d e r> .

Q: What are the syntax rules for XML document?

Ans: Y o u m u s t f o llo w th e s e ru le s w h e n yo u c rea te X M L s yn tax :

● A ll X M L e lem en ts m u s t h a ve a c lo s ing ta g .
● X M L ta g s a re c a s e s e n s itive .
● A ll X M L e lem en ts m u s t b e p ro p e rly n e s te d .
● A ll X M L d o c u m e n ts m u s t h a v e a ro o t elem e nt.
● A ttrib u te v a lu es m u s t a lw a ys b e q u o te d .

1. All XML elements must have a closing tag

It is ille g a l to o m it th e c lo s in g ta g w h e n yo u a re c rea tin g X M L s yn ta x . X M L e le m e n ts m u s t


h a ve a c lo s in g ta g .

E g : < b o d y> S e e S p o t ru n .< / b o d y>

< b o d y> S ee S p o t c a tc h th e b a ll.< / b o d y>

● X M L ta g s a re c a s e s e n s itive
● W h e n yo u c rea te X M L d o c u m en ts , th e ta g < B o d y> is d if feren t fro m th e ta g < b o d y > .
● A ll X M L e lem en ts m u s t b e p ro p e rly n e s te d
Im p ro p er n es tin g o f ta g s m a k es n o s e ns e to X M L .

< b > < i> T h is te xt is b o ld a n d ita lic .< /i> < /b >

2. XML tags are case sensitive

E le m e n t n a m ed w o n d e r, W O N D E R a n d W o n d e r a re c o n s id ered en tire ly s e p a ra te
a n d u n rela ted to e a c h o th er.

3. All XML elements must be properly nested: If yo u s ta rt ele m e n t A , th en s ta rt


ele m e n t B , yo u m u s t f irs t c lo s e e lem en t B b efo re c lo s in g e lem en t A .

Eg: < A >

< b > N a m e < /b >

</A>

4. All XML documents must have a root element

A ll X M L d o c u m en ts m u s t c o n ta in a s in g le ta g p a ir to d efin e a ro o t e lem en t. A ll o th er
ele m e n ts m u s t b e w ith in th is ro o t e le m e n t. A ll e le m en ts c an h a ve s u b elem e nts ( c h ild
ele m e n ts ) . S u b elem e n ts m u s t b e c o rrec tly n e s te d w ith in th e ir p a ren t ele m e n t.

Example:

< ro o t>

< c h ild >

< s u b c h ild > . .... < /s u b c h ild >

< /c h ild >

< / ro o t>

5. Attribute values must always be quoted

It is ille g a l to o m it q u o ta tio n m a rk s a ro u n d a ttrib u te v a lu es . X M L elem e n ts c a n h a v e


a ttrib u tes in n am e /v a lu e p a irs ; h o w e ve r, th e a ttrib ute v a lu e m u s t a lw a ys b e q u o te d .

< ? x m l ve rs io n = “ 1 .0 ” e n c o d in g = “ IS O -8 8 5 9 -1 ” ? >
< n o te d a te = ” 0 5 /0 5 / 0 5 ” >

< to > D ic k < / to >

< fro m > J a n e < /f ro m >

< / n o te>

Q: How to place comments in XML?

Ans: X M L c o m m en ts are s im ila r to H T M L c o m m e n ts . T h e c o m m en ts a re a d d e d a s n o tes


o r lin e s fo r u n d ers ta n d in g th e p u rp o s e o f a n X M L c o d e .

C o m m e n ts c a n b e u s ed to in c lu d e rela ted lin k s , in fo rm a tio n , an d te rm s . T h e y a re v is ib le


o n ly in th e s o u rc e c o d e; n o t in th e X M L c o d e. C o m m en ts m a y a p p ea r a n yw he re in X M L
co de .

Syntax

X M L c o m m en t h a s th e f o llo w in g s yn ta x −

< !--Y o u r c o m m en t-->

A c o m m e n t s ta rts w ith < !-- a n d en d s w ith --> . Y o u c a n a d d tex tu a l n o tes a s c o m m en ts


b e tw e en th e c h a ra c te rs . Y o u m u s t n o t n es t o n e c o m m e n t in s id e th e o th e r.

E g : < ? x m l v ers io n = "1 .0 " en c o d in g = "U T F -8 " ? >


< !--S tu d e n ts g ra d es a re u p lo a d ed b y m o n th s -

X M L C o m m en ts R u les

● C o m m e n ts c a n n o t a p p e ar b e fo re X M L d ec la ra tio n .
● C o m m e n ts m a y a p p e a r a n yw h ere in a d o c u m e n t.
● C o m m e n ts m u s t n o t a p p ea r w ith in a ttrib u te v a lue s .
● C o m m e n ts c a n n o t b e n es ted in s id e the o th er c o m m en ts .

Q: Write about DTD’ s (OR) Document Type Definitions?

Ans: T h e X M L D o c u m en t T yp e D e c la ra tio n , c o m m o n ly k n o w n a s D T D , is a w a y to d e s c rib e


X M L la n g u a g e p re c is ely. D T D s c h ec k v o c a b u la ry a n d v a lid ity o f th e s tru c tu re o f X M L
d o c u m en ts a g a in s t g ra m m a tic a l ru le s o f a p p ro p ria te X M L la n g u a g e .
A n X M L D T D c a n b e e ith e r s p ec ifie d in s id e th e d o c u m e n t, o r it c a n b e k ep t in a s e p a ra te
d o c u m en t a n d th en lik e d s ep a ra te ly.

Syntax

B a s ic s yn tax o f a D T D is a s f o llo w s −

< !D O C T Y P E e le m en t D T D id e ntifier
[
d ec la ra tio n 1
d ec la ra tio n 2
. ..... ..
]>

In th e a b o ve s yn ta x ,

● T h e D T D s ta rts w ith < !D O C T Y P E d elim iter.


● A n e le m e n t tells th e p a rs er to p a rs e the d o c u m en t fro m th e s p ec ifie d ro o t ele m e n t.
● D T D id en tif ie r is a n id e n tif ie r fo r th e d o c u m en t typ e d e fin itio n , w h ic h m a y b e th e
p a th to a file o n th e s ys tem o r U R L to a file o n th e in tern et. If th e D T D is p o in tin g to
ex te rn a l p a th , it is c a lled E xtern a l Su b s et.
● T h e s q u are b rac k ets [ ] en c lo s e a n o p tio n a l lis t o f e n tity d e c la ra tio n s c a lle d In tern a l
Su b s et.

Internal DTD

A D T D is refe rre d to a s a n in tern a l D T D if e lem en ts a re d e c la re d w ith in th e X M L files . T o


refe r it a s in te rn al D T D , s ta n d a lo n e a ttrib u te in X M L d ec la ra tio n m u s t b e s e t to yes . T h is
m ea n s , th e d e c la ra tio n w o rk s in d e p e n d en t o f a n ex tern a l s o u rc e.

Syntax

F o llo w in g is th e s yn ta x o f in te rn a l D T D −

< !D O C T Y P E ro o t-elem e nt [e le m en t-d e c la ra tio ns ]>

w h ere ro o t-elem en t is th e n a m e o f ro o t elem e n t a n d e lem en t-d e c la ra tio n s is w h ere yo u


d e c la re th e ele m e n ts .

E x a m p le

F o llo w in g is a s im p le e xa m p le o f in tern a l D T D −

< ? x m l ve rs io n = "1 .0 " e n c o d in g = "U T F -8 " s ta n d a lo n e = "yes " ? >


< !D O C T Y P E a d d res s [
< !E L E M E N T a d d re s s (n a m e ,c o m p a n y,p h o n e )>
< !E L E M E N T n a m e (# P C D A T A )>
< !E L E M E N T c o m p a n y (# P C D A T A ) >
< !E L E M E N T p h o n e (# PC D A TA )>
]>

< a d d res s >


< n a m e> T a n m a y P a til< / n a m e >
< c o m p a n y> T u to ria ls P o in t< /c o m p a n y>
< p h o n e > (0 1 1 ) 1 2 3 -4 5 6 7 < /p h o n e >
< / a d d re s s >

Le t u s g o th ro ug h th e ab o v e c o d e −

S ta rt D e c la ra tio n − B eg in th e X M L d e c la ra tio n w ith th e fo llo w in g s ta te m e n t.

< ? x m l ve rs io n = "1 .0 " e n c o d in g = "U T F -8 " s ta n d a lo n e = "yes " ? >

DTD − Im m e d ia tely a fte r th e X M L h e a d e r, th e d o c um e n t ty p e d e c la ra tio n f o llo w s ,


c o m m o n ly refe rre d to a s th e D O C TY P E −

< !D O C T Y P E a d d res s [

T h e D O C T Y P E d ec la ra tio n h a s an ex c la m atio n m a rk (!) a t th e s ta rt o f th e ele m e n t n a m e .


T h e D O C T Y P E in fo rm s th e p a rs er tha t a D T D is as s o c ia ted w ith th is X M L d o c u m e n t.

D T D B o d y − T h e D O C T Y P E d ec la ra tio n is fo llo w e d b y b o d y o f th e D T D , w h e re yo u d e c la re
ele m e n ts , a ttrib u te s , en titie s , a n d n o ta tio n s .

< !E L E M E N T a d d re s s ( n a m e ,c o m p a n y,p h o n e )>


< !E L E M E N T n a m e ( # P C D A T A )>
< !E L E M E N T c o m p a n y ( # P C D A T A )>
< !E L E M E N T p h o ne _ no (# P C D A T A ) >

S ev era l elem en ts a re d e c la re d h e re th a t m a k e u p th e v o c a b u la ry o f th e < n a m e > d o c u m en t.


< !E LE M E N T n a m e (# P C D A T A )> d ef in e s th e e lem en t n a m e to b e o f typ e "# P C D A T A ". H ere
# P C D A T A m e an s p a rs e -a b le te xt d a ta .

E n d D e c la ra tio n − F in ally, th e d ec la ra tio n s ec tio n o f th e D T D is c lo s ed u s in g a c lo s in g


b ra c k et a n d a c lo s in g a n g le b ra c k e t (]> ) . T h is e ffe c tive ly en d s th e d ef in itio n , a n d
th erea fte r, th e X M L d o c u m en t fo llo w s im m ed ia te ly .
R u le s
● T h e d o c u m en t typ e d e c la ra tio n m u s t a p p ea r a t th e s ta rt o f th e d o c u m en t
(p rec ed ed o n ly b y th e X M L h e a d e r) − it is no t p e rm itte d a n yw h e re e ls e w ith in th e
d o c u m e n t.
● S im ila r to th e D O C T Y P E d ec la ra tio n , th e e le m en t d ec la ra tio n s m u s t s ta rt w ith a n
ex c la m a tio n m a rk .
● T h e N a m e in th e d o c u m e n t typ e d ec la ra tio n m u s t m a tc h the e le m e n t typ e o f th e
ro o t elem en t.

External DTD

In ex te rn al D T D ele m e n ts a re d ec la re d o u ts id e th e X M L file. T h e y a re a c c es s e d b y
s p e c ifyin g th e s ys tem a ttrib u tes w h ic h m a y b e e ith e r th e leg a l .d td file o r a v a lid U R L. T o
refe r it a s ex tern a l D T D , s ta n d a lo n e attrib u te in th e X M L d e c la ra tio n m u s t b e s e t a s n o .
T h is m e an s , d ec la ra tio n in c lu d e s in fo rm a tio n fro m th e e xtern a l s o u rc e .

Syntax
< !D O C T Y P E ro o t-elem e nt S Y S T E M "file -n a m e">

w h ere file-na m e is the file w ith .d td e xten s io n .

Example

T h e fo llo w in g e xa m p le s h o w s e xtern a l D T D u s a g e −

< ? x m l ve rs io n = "1 .0 " e n c o d in g = "U T F -8 " s ta n d a lo n e = "n o " ? >


< !D O C T Y P E a d d res s S Y S T E M "a d d re s s .d td ">
< a d d res s >
< n a m e> T a n m a y P a til< / n a m e >
< c o m p a n y> T u to ria ls P o in t< /c o m p a n y>
< p h o n e > (0 1 1 ) 1 2 3 -4 5 6 7 < /p h o n e >
< / a d d re s s >

T h e c o n ten t o f th e D T D file a d d res s .d td is a s s h o w n −

< !E L E M E N T a d d re s s ( n a m e ,c o m p a n y,p h o n e )>


< !E L E M E N T n a m e ( # P C D A T A )>
< !E L E M E N T c o m p a n y ( # P C D A T A )>
< !E L E M E N T p h o ne (# P C D A T A )>

Q: What are the basic building blocks of DTD?


Ans: All XML elements are made up by the following building blocks:
1 . E le m e n ts
2 . A ttrib u te s
3 . E n tites
4. P CD ATA
5. CD ATA

Elements:-

E le m e n ts a re th e m a in b u ild in g b lo c k s o f X M L d o c u m en ts . In a D T D , X M L e le m en ts a re
d e c la red w ith a n e le m e n t d ec la ra tio n w ith th e f o llo w in g s yn ta x :

< !E L E M E N T elem e nt-n a m e c a te g o ry>


or
< !E L E M E N T elem e nt-n a m e (e lem en t-c o n ten t)>

a . E m p ty E le m e n ts
E m p ty ele m e n ts a re d ec la red w ith th e c a teg o ry k e yw o rd E M P T Y :

< !E L E M E N T elem e nt-n a m e E M P T Y >

E x a m p le:

< !E L E M E N T b r E M P TY >

b. Elements with Parsed Character Data

E le m e n ts w ith o n ly p ars e d c h a ra c te r d a ta a re d e c la re d w ith # P C D A T A in s id e p a ren th es e s :

< !E L E M E N T elem e nt-n a m e (# P C D A T A )>


E x a m p le:

< !E L E M E N T fro m ( # P C D A T A )>

c. Elements with any Contents

E le m e n ts d e c la re d w ith the c a te g o ry k eyw o rd A N Y , c a n c o n ta in a n y c o m b in a tio n o f


p a rs a b le d a ta :

< !E L E M E N T elem e nt-n a m e A N Y >

E x a m p le:

< !E L E M E N T n o te A N Y >

d. Elements with Children (sequences)

E le m e n ts w ith o n e o r m o re c h ild re n a re d ec lare d w ith th e n a m e o f th e c h ild ren elem en ts


in s id e p a re n th e s es :

< !E L E M E N T elem e nt-n a m e (c h ild 1 )>


or
< !E L E M E N T elem e nt-n a m e (c h ild 1 , c h ild 2 ,… ) >

Example:

< !E L E M E N T b o o k (title, a u th o r, in fo , b o d y)>

W h e n c h ild re n a re d ec la red in a s eq u en c e s ep ara ted b y c o m m a s , th e c h ild ren m u s t


a p p ea r in th e s a m e s eq u en c e in th e d o c u m e n t. In a fu ll d ec la ra tio n , th e c hild re n m u s t a ls o
b e d e c la red , a n d th e c h ild ren c a n a ls o h a v e c h ild re n . T h e fu ll d ec la ra tio n o f th e “ n o te”
ele m e n t is :
< !E L E M E N T b o o k (title, a u th o r, in fo , b o d y)>
< !E L E M E N T title (# P C D A T A )>
< !E L E M E N T a u th o r (# P C D A T A )>
< !E L E M E N T in f o (# P C D A T A )>
< !E L E M E N T b o d y (# P C D A T A )>

2) Attributes:- A ttrib u tes p ro v id e e xtra in fo rm a tio n a b o u t ele m e n ts . A ttrib u te s a re alw a ys


p la c ed in s id e th e o p e n in g ta g o f a n e lem en t. A ttrib u te s a lw a ys c o m e in n a m e/ va lu e p a irs .

T h e n a m e o f th e e lem en t is “ p a ym e n t” . T h e n a m e o f th e a ttrib u te is “ typ e ” . T h e


v alu e o f a ttrib u te is “ c h ec k ” . S in c e th e e le m e n t its elf is e m p ty it is c lo s ed b y a ” / ” . In
a D T D , a ttrib u te s a re d e c la red w ith a n A T T L IS T d e c la ra tio n . A n a ttrib u te d e c la ra tio n h a s
th e fo llo w in g s yn ta x:

< !A T T LIS T e lem en t-n a m e a ttrib u te-n a m e a ttrib u te-typ e d efa u lt-va lu e>

D T D e xa m p le :

< !A T T LIS T p a ym e n t typ e C D A T A “ c h e c k ” >

T h e d efa u lt-va lu e c a n b e o ne o f th e fo llo w in g :

V a lu e E x p la n a tio n

T h e d e fa u lt v a lu e o f th e a ttrib u te
V a lu e

# R E Q U IR E D T h e a ttrib u te is re q u ire d

# IM P L IE D T h e a ttrib u te is n o t req u ire d


T h e a ttrib u te va lu e is fixe d
# F IX E D v a lu e

3) Entities:-
S o m e c h a ra c te rs h a v e a s p ec ia l m ea n in g in X M L, lik e th e les s th a n s ig n (< ) th a t d e fin es
th e s ta rt of an XML ta g . M o st of us know th e HTM L e n tity: ” “ . T h is
“ n o -b rea k in g -s p a c e ” e n tity is u s e d in H T M L to in s ert a n e xtra s p a c e in a d o c u m en t.
E n titie s are e xp a n d e d w h en a d o c u m e n t is p a rs ed b y a n X M L p a rs e r.

T h e fo llo w in g e n tities a re p red efin e d in X M L:

E n tity R efe ren c e s C h a ra c ter

& lt; <

& g t; >

&amp; &

& q u o t; “

& apo s; ‘

4) PCDATA:- P C D A T A m ea n s . W e c a n th in k o f c ha ra c te r d a ta a s
th e te xt fo u n d b etw ee n th e s ta rt ta g a n d th e en d ta g o f a n X M L e le m e n t. It is th e tex t th a t
w ill b e p a rs ed b y a p a rs e r. T h e te xt w ill b e e xa m ine d b y th e p a rs e r fo r e n tities a n d m a rk u p .
T a g s in s id e th e te xt w ill b e tre a ted a s m a rk u p a n d e n titie s w ill b e e xp a n d ed . H o w ev er,
p a rs e d c h a rac ter d a ta s h o u ld n o t c o n ta in a n y & , < , o r > c h a ra c te rs ; th e s e n ee d to b e
rep re s en ted b y th e & < a n d > e n tities , res p ec tiv ely.
5) CDATA:- C D A T A m e a n s c h a ra c ter d a ta . C D A T A is th e te xt th a t w ill n o t b e p a rs ed b y a
p a rs e r. T a g s in s id e th e tex t w ill n o t b e trea te d a s m a rk u p a n d en titie s w ill n o t b e
ex p a n d ed .

Q: How to create XML with CSS?

Ans: X M L s ta n d s fo r E xten s ib le M a rk u p L a ng u a g e . It is a d yn a m ic m a rk u p la n g u a g e. It is
u s ed to tra n s fo rm d a ta fro m o n e fo rm to a n o th e r fo rm .
A n X M L file c a n b e d is p la yed u s in g tw o w a ys . T h es e a re a s fo llo w s :-
1. C a s c a d in g S tyle S h ee t
2. E x ten s ib le S tyles h e et La n g u a g e T ra ns f o rm a tio n
Displaying XML file using CSS :
C S S c a n b e u s ed to d is p la y th e c o n ten ts o f th e X M L d o c u m en t in a c le a r a n d p re c is e
m a n n er. It g ive s th e d es ig n a n d s tyle to w ho le X M L d o c u m en t.
● Basic steps in defining a CSS style sheet for XML :
F o r d e fin in g th e s tyle ru les fo r the X M L d o c u m e n t, th e fo llo w in g th in g s s h o u ld b e d o n e :
-
1 . D e fin e th e s tyle ru les fo r th e tex t e le m en ts s u c h a s f o n t-s ize , c o lo r, fo n t-w eig h t, e tc .
2 . D e fin e e a c h ele m e n t e ith e r a s a b lo c k , in lin e o r lis t ele m e n t, u s in g th e d is p la y
p ro p erty o f C S S .
3 . Id en tify th e title s an d b o ld th e m .
● Linking XML with CSS :

In o rd er to d is p la y th e X M L file u s in g C S S , lin k X M L file w ith C S S . B e lo w is th e s yn ta x


fo r lin k in g th e X M L file w ith C S S :

Example1.

T h e X M L f ile is c rea ted th a t c o n ta in s th e in fo rm a tio n a b o u t fiv e b o o k s a n d d is p la yin g th e


X M L file u s in g C S S .
C re a tin g B o o k s .x m l a s :-

< ? x m l ve rs io n = "1 .0 " en c o d in g = "U T F -8 "? >


< ? x m l-s tyles h e et typ e= "te xt/ c s s " h re f= "R u le.c s s "? >
<bo oks>
< h ea d in g > W elc o m e T o G e ek s fo rG ee k s < / h ea d in g >
<bo ok>
< title> T itle -: W e b P ro g ra m m in g < / title>
< a u th o r> A u th o r -: C h ris b a tes < / a u th o r>
< p ub lis h e r> P u b lis h er -: W ile y< /p u b lis h er>
< e d itio n > E d itio n -: 3 < /e d itio n >
< p ric e > P ric e -: 3 0 0 < / p ric e >
</bo ok>
<bo ok>
< title> T itle -: In tern e t w o rld -w id e -w eb < /title >
< a u th o r> A u th o r -: D itel< /a u th o r>
< p ub lis h e r> P u b lis h er -: P e a rs o n < /p u b lis h er>
< e d itio n > E d itio n -: 3 < /e d itio n >
< p ric e > P ric e -: 4 0 0 < /p ric e >
</bo ok>
<bo ok>
< title> T itle -: C o m p u ter N e tw o rk s < / title>
< a u th o r> A u th o r -: F o ru o u z a n < /a u th o r>
< p ub lis h e r> P u b lis h er -: M c G ra w H ill< / p u b lis h er>
< e d itio n > E d itio n -: 5 < /e d itio n >
< p ric e > P ric e -: 7 0 0 < /p ric e >
</bo ok></bo oks>

In th e a b o ve e xa m p le , B o o k s .x m l is lin k e d w ith R u le. c s s w h ic h c o n ta in s th e


c o rre s p o n d in g s tyle s h e et ru le s .

● CSS FILE :

C re a tin g R u le. c s s a s :-

bo oks {
c o lo r: w h ite ;
b a c k g ro u n d -c o lo r : g ra y;
w id th : 1 0 0 % ;
}
h ea d in g {
c o lo r: g re en ;
fo n t-s iz e : 4 0 p x;
b a c k g ro u n d -c o lo r : p o w d erb lu e ;
}
h ea d in g , title, a u th o r, p u b lis h e r, ed itio n , p ric e {
d is p la y : b lo c k ;
}
title {
fo n t-s iz e : 2 5 p x;
fo n t-w e ig h t : b o ld ;
}

Q: What are the differences between XML and HTML?

Ans:

N HTM L XML
o.

1) H T M L is u s e d to d is p la y d a ta a n d X M L is a s o ftw a re an d h a rd w a re in d ep en d en t to o l u s e d to
fo c u s es o n h o w d a ta lo o k s . tra n s p o rt a n d s to re d a ta . It fo c u s es o n w h a t d a ta is .

2) H T M L is a m a rk u p la n g u a g e its e lf . X M L p ro v id es a fram e w o rk to d efin e m a rk u p la n g u a g e s .

3) H T M L is n o t c a s e s e n s itive . X M L is c a s e s en s itiv e.

4) H T M L is a p res e n ta tio n la ng u a g e . X M L is n e ith e r a p re s en ta tio n la n g u a g e n o r a p ro g ram m ing


la n g u a g e .

5) HTM L has its own p re d e fin ed Y o u c a n d efin e ta g s a c c o rd ing to yo u r n e ed .


ta g s .

6) In H T M L, it is n o t n e c e s s ary to u s e X M L m a k e s it m a n d a to ry to u s e a c lo s in g ta g .
a c lo s in g ta g .

7) H T M L is s ta tic b ec a u s e it is u s ed X M L is d yn a m ic b e c a u s e it is u s e d to tra n s p o rt d ata .


to d is p la y d a ta .

8) HTM L d oe s not p re s erve X M L p res e rv e w h ite s p a c e s .


w h ites p a c e s .

Q: Define DOM?

Ans: The D oc um e nt O b jec t M o del (DO M ) is a p ro g ra m m in g


in te rfa c e f o r H T M L (H yp e rT ex t M a rk u p La n g u a g e ) a n d X M L (E x te n s ib le m a rk u p
la n g u a g e ) d o c u m en ts . It d e fin e s th e lo g ic a l s tru c tu re o f d o c u m e n ts a n d th e w a y a
d o c u m e n t is a c c e s s e d a n d m a n ip u la te d .

You might also like