Web technology
Web technology
Q: Define XML?
(O R )
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.
Ans:
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 .
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 .
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 .
H ere a re s o m e e xa m p le s :
o XHTML
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
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
w h ere,
Empty Element
OR
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 .
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:
● 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 .
● 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 >
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.
</A>
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>
< / ro o t>
< ? 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 ” >
< / n o te>
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 −
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 .
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 ,
Internal DTD
Syntax
F o llo w in g is th e s yn ta x o f in te rn a l D T D −
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 −
Le t u s g o th ro ug h th e ab o v e c o d e −
< !D O C T Y P E a d d res s [
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 .
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">
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 −
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 :
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 x a m p le:
< !E L E M E N T b r E M P TY >
E x a m p le:
< !E L E M E N T n o te A N Y >
Example:
< !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 :
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
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.
& g t; >
& &
& 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 .
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 :
Example1.
● 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 ;
}
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 .
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.
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 .
Q: Define DOM?