You are on page 1of 8

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

UNIVERSITI TEKNOLOGI MARA


FINAL EXAMINATION

COURSE

XML PROGRAMMING

COURSE CODE

CSC570/ITC570

EXAMINATION

JANUARY 2012

TIME

3 HOURS

INSTRUCTIONS TO CANDIDATES
1.

This question paper consists of two (2) parts

2.

Answer ALL questions in the Answer Booklet. Start each answer on a new page.

3.

Do not bring any material into the examination room unless permission is given by the
invigilator.

4.

Please check to make sure that this examination pack consists of:
i)
ii)

PART A (6 Questions)
PART B (3 Questions)

the Question Paper


an Answer Booklet - provided by the Faculty

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 8 printed pages
Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

PART A (60 MARKS)

QUESTION 1
Extensible Markup Language (XML) is a set of rules for encoding documents in machinereadable form. It is defined in the XML 1.0 Specification produced by the W3C, and several
other related specifications. Technically, an XML document is made up from three parts
which are prolog, document element (usually containing nested elements) and optional
comments.
a) Describe THREE (3) benefits of XML language.
(6 marks)
b) List THREE (3) items that can be contained in prolog Give an appropriate example for
each of the item.
(6 marks)
QUESTION 2
DTD defines the legal building blocks of an XML document.
a) Write a DTD for the following description:
The root element SATU must contain precisely one element DUA followed by one
element TIGA. Elements DUA and TIGA can contain some text but no other elements.
(2 marks)
b) Assume that a) is saved in a file called final.dtd. Explain, why the following XML
documents are consider invalid.
i)

<!DOCTYPE SATU SYSTEM "final.dtd">


<SATU> <DUA/> </SATU>

ii)

<!DOCTYPE SATU SYSTEM "final, dtd" >


<SATU> <TIGA/> <DUA/> </SATU>

iii)

<!DOCTYPE SATU SYSTEM "final, dtd" >


<SATU> <DUA/> <TIGA/> <TIGA/> </SATU>

iv)

<!DOCTYPE SATU SYSTEM "final, dtd" >


<SATU> Elements: <DUA/> <TIGA/> </SATU>
(8 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

QUESTION 3
Given below is XML document (named warna.xml) that contains information about color.

<?xml v e r s i o n = " l . 0 " ? >


<?xml - s t y l e s h e e t type="it e x t / x s l "
<warna>
putih
<sewarna>
j ingga
< t on_warna1>
perang
<ton warna2>
kelabu
</sewarna>
h i tarn
<warna kroma>
h i j au
<ton warna3>
magenta
< t on_warna4 >
b i r u muda
</warna_kroma>
merah
<warna n e u t r a l >
merah h a t i
<ton_warna3 >
cyan
<ton_warna4 >
biru laut
</warna_neutral>
biru
</warna>

Hak Cipta Universiti Teknologi MARA

href="warna.xsl"?>

perak</ton_warnal>
etnas</ton warna2>

n i l a < / t o n warna3>
v i o l e t < / t o n warna4>

ungu</ton_warna3 >
z a i t u n < / t o n warna4>

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

Write the output extracted from the XSL file (warna. x s l ) below.
<?xml version="l.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="warna">
<pre>
Warna Tambahan putih.
<xsl:apply-templates select="sewarna"/>
Warna Tambahan hitam.
<xsl:apply-templates select="warna_kroma"/>
Warna Tambahan merah.
<xsl:apply-templates select="warna_neutral"/>
Warna Tambahan biru.
</pre>
</xsl:template>
<xsl:template match="sewarna">
Warna Tambahan jingga.
<xsl:apply-templates select "ton_warnal"/>
Warna Tambahan perang.
<xsl:apply-templates select "ton warna2"/>
Warna Tambahan kelabu.
</xsl:template>
<xsl:template match="warna_kroma">
Warna Tambahan hijau.
</xsl:template>
</xsl:stylesheet>
(10 marks;
QUESTION 4
Consider the following segment of the XML document, where <menu> is the root element.
1

<menu>

<chinese>

3
4
5

6
7

<dish lang="en">dim sum</dish>


<price>35.00</price>
<chief> Johan Kamal Ali</chief>

</chinese>
</menu>

What element(s) does each of the XPath expression select from the XML document? Use
the number of line for the answer.
a)
b)
c)
d)

Chinese
/Chinese
/ c h i n e s e / d i s h [price>25 . 00]
//chinese/dish

(8 marks)
Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

QUESTION 5
The XML DOM presents an XML document as a tree-structure. It defines a standard way for
accessing and manipulating XML documents. We can access, change, add and delete
nodes in XML documents.
a)

Identify TWO (2) ways to access nodes using XML DOM.


(2 marks)

b)

Below is the XML document that contains data regarding courses offered by a faculty.
<?xml version="l.0"?>
<FSKM>
<course>
<program> CS23 0 </program>
<code> BEL492 </code>
<prerequisite> none </prerequisite>
<name> PRESENTATION SKILLS </name>
<credit hours> 2 </credit hours>
</course>
<course>
<program> CS23 0 </program>
<code> CSC415 </code>
<prerequisite> CSC101 </prerequisite>
<name> Fundamental of Computer Problem Solving </name>
<credit_hours> 4 </credit hours>
</course>
<course>
<program> CS23 0 </program>
<code> CSC428 </code>
<prerequisite> none </prerequisite>
<name> Computer Organization </name>
<credit_hours> 4 </credit hours>
</course>
</FSKM>

Write a segment of code in JavaScript in order to execute the following statements:


i) Display all name for each course.

ii) Change the value of course name from "Computer


"Computer S t r u c t u r e " .

Organization" to

iii) Remove the element of p r e r e q u i s i t e for "Fundamental


Problem Solving" course.

of

Computer
(6 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

QUESTION 6
Below are the statements about XML Schemas. State whether each of the statement is
TRUE or FALSE.
a)

Unlike DTDs, XML Schemas must always be external to the XML file.

b)

An XML schema is a description of XML document, typically expressed in terms of


constraints on the structure and content of documents of that type, above and
beyond the basic syntactical constraints imposed by XML itself.

c)

The namespace should be specified exactly as required because the browser


associates a schema file with the particular URL which works as a system file.

d)

A content model defines the type of content that can be contained in an attribute.

e)

An element that contains no content type of model is called a complex element.

f)

Attributes may have three attribute values associated with them, which determine
their initial value. They are required, fixed and use.

g)

Complex type elements are divided into two groups: those with simple content and
those with complex content.

h)

Complex content is used when you want your element to have child elements and
attributes.
(12 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

PART B (40 MARKS)

QUESTION 1
The following code named p e r s o n a l . d t d contains the document type declaration of
personal XML document named p e r s o n e l .xml.
<!ELEMENT personel (person)+>
<!ELEMENT person

(name,email*,url*,sub_relation?)>

<!ATTLIST person id ID #REQUIRED>


<!ELEMENT family (#PCDATA)>
<!ELEMENT name

(#PCDATA|family)*>

<!ELEMENT email (#PCDATA)>


<!ELEMENT url EMPTY>
<!ATTLIST url href CDATA #REQUIRED>
<!ELEMENT sub_relation EMPTY>
<!ATTLIST sub_relation parent IDREF #IMPLIED
child IDREFS #IMPLIED>

Write an XSLT Stylesheet that sorts the p e r s o n e l . x m l file based on the family name
according to alphabetical order. For each name, it also displays the family name, person's
i d , e m a i l , u r l and s u b _ r e l a t i o n of the personnel records as an HTML file.
Sample output using browser:
FAMILY NAME: Boon-Siew
ID: father
EMAIL: admin@boonsiew.com.my
URL: http://www.boonsiewmotor.com.my
SUB-RELATION: childA
FAMILY NAME: Fa-Kor
ID: childA
EMAIL: contact@morfakor.tv
URL: http://www.morfakor.tv
SUB-RELATION: father

(12 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC570/ITC570

QUESTION 2
Assume that we want to define part of an XML document that contains elements
C u r r e n t A d d r e s s and Home_Address. Both elements contain the same information
represented using elements in the following sequence: houseNo, s t r e e t , an optional
s e c t i o n or v i l l a g e , town and postcode. Without repeating the content model
definition for c u r r e n t _ A d d r e s s and Home_Address, give the necessary declarations as
part of
a)
b)

a DTD and
an XML schema.
(14 marks)

QUESTION 3
The following is a list of description of UiTM Academic Calendar ( u i t m c a l e n d a r . xml).

The root element is "Academic_Calendar".


As the content for root element, "Session" occurs 0 or more times and "Notes".
The "Session" contains "Activity", "Date_Begin", "Date_End" and
"Length_of_Time" elements that occur once in respective order.
"Activity" and "Length_of_Time" content are text strings while "Date_Begin" and
"Date_End" content must be in date type.
"Session" has two attributes called "Session_Number" and "Year".
"Session_Number" content must be in integer type and "Year" can be strings.
"Notes" may contain any type of data, other additional elements or empty.

Write the definition for the structure of XML document described above by using
a)
b)

a DTD and
an XML schema.
(14 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

You might also like