Quiz 2 solution

advertisement
MSc Internet Computing Quiz 2
April 23, 2001
Name:
Student No.:
Program:
ALL questions in the quiz should be answered.
1. (a) Name 4 major components of an XML document? (4 marks)
–elements
–attributes
–comments
–processing instructions
(b) Write a DTD for an XML document for dissertation project reports. Each report
has a cover page, a table of contents, may or may not have a table of figures, an
abstract, a number of chapters and within each chapters there may be sections and/or
subsections, references and optionally an index. Use attributes to contain information
about the author name, student ID and supervisor name in the root element. (6 marks)
<!DOCTYPE report [
<!ELEMENT report (COVER,TOC, TOF?, abstract, chapter+,
reference, index?)>
<!ELEMENT COVER (#PCDATA)>
<!ELEMENT abstract (#PCDATA)>
<!ELEMENT TOC (#PCDATA)>
<!ELEMENT TOF (#PCDATA)>
<!ELEMENT chapter (section*)>
<!ELEMENT section (PCDATA | subsection*)>
<!ELEMENT subsection (#PCDATA)>
<!ELEMENT reference (#PCDATA)>
<!ELEMENT index (#PCDATA)>
<!ATTLIST report
author_name CDATA #REQUIRED
student_ID CDATA #REQUIRED
supervisor_name CDATA #REQUIRED
>
]>
2. (a) Describe in general terms how XSL transformations are performed. (4 marks)


Build a new XML tree from the original tree
XSL provides operators to select particular nodes form the tree, re-ordering
the nodes, and outputting the nodes
 XSL transformation is carried out by a set of template rules, as defined in
style sheet
 Each rule has a pattern for matching and a template to output
 Matching is done recursively starting from XML root node
 If a rule is matched, the corresponding template is output.
(b) Write an XSL stylesheet to convert the follow XML document into an HTML
document. The output document should highlight the sections in a header element
(i.e. <h1>). The marks should be displayed with the questions in a bulleted list. (6
marks)
<?xml version=”1.0”?>
<!DOCTYPE exam “http://here/this.html”>
<exam>
<SectionA>
<Q mark =”25”>Question 1</Q>
<Q mark =”25”>Question 2</Q>
</SectionA>
<SectionB>
<Q mark =”50”>Question 3</Q>
</SectionB>
<?xml version=”1.0”>
<xsl:stylesheet
xmlns:xsl=”http://www.w3c.org/XSL/Transform/1.0”
<xsl:template match=”exam”>
<html><head></head><body>
<xsl:apply-templates/>
</body></html>
</xsl:template>
<xsl:template match=”SectionA”>
<h1>SectionA<h1>
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match=”Q”>
<li>
<xsl:value-of select=”.” />
(Mark
<xsl:value-of select=”./@mark” />
)
</li>
</xsl:template>
Same for SectionB
</xsl:stylesheet>
3 (a) Discuss 4 problems in DTD when comparing with XML Schema. (4 marks)
?>
•Different syntax than regular XML
•No datatypes and complex to extend
•No length, occurrences controls
•Only 10 data types
•Namespaces not well support
•No inheritance (no kind-of information, only part-of information)
•Insufficient checking: too much work is left to application
(b) Convert the following DTD into XML Schema. (6 marks)
(NAME, HIREDATE, MANAGER, DEPARTMENT)>
<!ELEMENT EMPLOYEE (NAME, HIREDATE, SUPER?, DEPARTMENT+)>
<!ATTLIST EMPLOYEE employment-category (full | part | hourly) #REQUIRED>
<!ATTLIST EMPLOYEE empid ID #REQUIRED>
<!ELEMENT NAME #PCDATA>
<!ELEMENT HIREDATE #PCDATA>
<!ELEMENT SUPER #PCDATA>
<!ELEMENT DEPARTMENT #PCDATA> <?xml version="1.0"?>
<xsd:schema xmlns:xsd=http://www.w3.org/2000/10/XMLSchema>
<xsd:element name=“EMPLOYEE">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="NAME" minOccurs="1" maxOccurs="1"/>
<xsd:element ref=“HIREDATE" minOccurs="1" maxOccurs="1"/>
<xsd:element ref=“SUPER" minOccurs="0" maxOccurs="1"/>
<xsd:element ref=“DEPARTMENT" minOccurs="1" maxOccurs="*"/>
<<attributeType name="empidy" dt:type="ID">
<<attributeType name="employment-category" dt:type="enumeration"
dt:vdt:values="full part hourly">
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name=“NAME" type="xsd:string"/>
<xsd:element name=“HIREDATE" type="xsd:string"/>
<xsd:element name=“SUPER" type="xsd:string"/>
<xsd:element name=“DEPARTMENT" type="xsd:string"/>
</xsd:schema>
4. (a) Convert the following HTML file into a WML file. (6 marks)
<html>
<HEAD>
<TITLE> Lab 1 </TITLE>
<BODY><h3>At the beginning</h3>
<ul>
<li> Set up your homepages in <a href="home.html">COMP</a> </li>
<li> Basic <a href="cgi.html">COMP</a>. </li>
<li> Create <a href="form1.html">this form </a>. </li>
<li> Get data from <a href="post1.html">POST action type</a>.
</ul>
</body>
</html>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title=" Lab 2 ">
<p>At the beginning<p>
Set up your homepages in <a href="home.html">COMP</a> <p>
Basic <a href="cgi.html">COMP</a><p>
Create <a href="form1.html">this form </a>.<p>
Get data from <a href="post1.html">POST action type</a>.<p>
</p>
</card>
</wml>
(b) What are the two major differences between WAP and Web programming? (4 marks)
Two crucial difference:
•WAP proxy or gateway to translate user agent request to HTTP and vice
versa
•Communications between proxy and user agent is done by WAP protocol
stacks, which is essentially a compact and binary form of HTTP 1.1.
Download