Tribhuwan University

Institute of Science and Technology

2081

Bachelor Level / Third Year / Fifth Semester / Science

B.Sc in Computer Science and Information Technology (CSC329)

(Web Technology)

Full Marks: 60

Pass Marks: 24

Time: 3 Hours

Candidates are required to give their answers in their own words as for as practicable.

The figures in the margin indicate full marks.

Section A

Long Answers Questions

Attempt any TWO questions.
[2*10=20]
1.
Describe the rules for creating XML document. Create a XML file with simple type and elements with attribute and nested elements. Write its equivalent XSD.[10]

Rules for Creating XML Document with Example and XSD

XML (eXtensible Markup Language) is a markup language used to store and transport data in a structured, self-descriptive format that is both human-readable and machine-readable.


Rules for Creating a Well-Formed XML Document

  • Rule 1: Every XML document must have exactly one root element that contains all other elements.
  • Rule 2: All XML elements must have a closing tag (e.g., <name>...</name>) or be self-closing (e.g., <br/>).
  • Rule 3: XML tags are case-sensitive<Name> and <name> are different.
  • Rule 4: XML elements must be properly nested — tags cannot overlap (e.g., <b><i>text</i></b> is correct).
  • Rule 5: Attribute values must always be enclosed in quotes (single or double).
  • Rule 6: The XML document should begin with an XML declaration: <?xml version="1.0"?>.
  • Rule 7: Element names must start with a letter or underscore, not a number or special character.
  • Rule 8: No reserved characters like <, >, & should be used directly in content — use entity references (&lt;, &gt;, &amp;).
  • Rule 9: White spaces are preserved in XML (unlike HTML).
  • Rule 10: Comments are written as <!-- comment --> and cannot appear inside tags.

XML File Example (With Simple Type, Attributes, and Nested Elements)

<?xml version="1.0" encoding="UTF-8"?>
<library>
    <book id="101" category="fiction">
        <title>The Alchemist</title>
        <author>Paulo Coelho</author>
        <price>350.00</price>
        <publisher>
            <name>HarperCollins</name>
            <country>USA</country>
        </publisher>
    </book>
    <book id="102" category="science">
        <title>A Brief History of Time</title>
        <author>Stephen Hawking</author>
        <price>500.00</price>
        <publisher>
            <name>Bantam Books</name>
            <country>UK</country>
        </publisher>
    </book>
</library>

Explanation:

  • libraryRoot element
  • book — Element with attributes (id, category)
  • title, author, priceSimple type elements (contain only text)
  • publisherNested element containing child elements (name, country)

Equivalent XSD (XML Schema Definition)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="library">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="book" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="title" type="xs:string"/>
                            <xs:element name="author" type="xs:string"/>
                            <xs:element name="price" type="xs:decimal"/>
                            <xs:element name="publisher">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="name" type="xs:string"/>
                                        <xs:element name="country" type="xs:string"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="id" type="xs:integer" use="required"/>
                        <xs:attribute name="category" type="xs:string" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

Key Points of XSD:

  • xs:string, xs:decimal, xs:integerSimple types for elements
  • xs:complexType — Used for elements that have child elements or attributes
  • xs:sequence — Ensures child elements appear in a specific order
  • xs:attribute — Defines attributes with use="required" to make them mandatory
  • maxOccurs="unbounded" — Allows multiple book elements

Conclusion

XML provides a flexible way to structure data with strict well-formedness rules. XSD validates the structure, data types, and constraints of an XML document, ensuring data integrity and consistency.

2.
Create an HTML file containing form with textbox, select and radio button. Now write a javascript function for validating the form elements. Validate textbox for required, select field should have some value selected and radio button should be checked.[10]
3.
Write a PHP program to create a form. Create an insertdb() method to insert the form values into a database table and display() to display the database table value.[10]
Section B

Short Answers Questions

Attempt any Eight questions.
[8*5=40]
4.
Write a HTML script to create a table with three rows and three columns. The second row third column should contain a text 'TU' with link set to www.tu.edu.np. The height of second row should be set to 200px. [5]
5.
What is onload event in HTML? Write an HTML script that displays alert message 'Hello Nepal' in onload event. [5]
6.
How internal and external CSS differ from each other. Illustrate with example. [5]
7.
How can you define array in javascript? Create an array Fruit with its elements 'apple', 'banana', 'mango', 'grape' and print the array. [5]
8.
How can you transform XML document into HTML using XSLT. Support your answer with an example. [5]
9.
Write a PHP function add that takes two arguments as an input and return their sum. [5]
10.
Define cookie. Write a PHP program to create and retrieve a cookie. [5]
11.
What is text-overflow property in CSS? How can you use clip and ellipsis in text-overflow? [5]
12.
Describe client server architecture with its types. [5]