CS311 – Introduction to Web Services Development: Midterm Important Subjective (43 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS311 Course Page · CS311 MCQ Pack (129 MCQs)
-
Why is UTF-8 encoding important in XML?
Topic: XML Basics, Syntax & Well-Formedness
UTF-8 encoding prevents character encoding problems and supports characters from different languages.
-
Write the XML declaration statement.
Topic: XML Basics, Syntax & Well-Formedness
<?xml version="1.0" encoding="UTF-8"?>
-
Write any five features of XML.
Topic: XML Basics, Syntax & Well-Formedness
1. XML is extensible. 2. XML is platform independent. 3. XML is self-descriptive. 4. XML stores and transports data. 5. XML is human readable.
-
Correct the following XML code: <to/>student<to> <From>teacher<from> <Body>upload assignment this weekend</body>
Topic: XML Basics, Syntax & Well-Formedness
Correct code: <to>student</to> <From>teacher</From> <Body>upload assignment this weekend</Body> Rules to remember: every opening tag must have a closing tag; tags are case-sensitive; and the XML document must be properly nested.
-
Write the XML syntax for the element "window".
Topic: XML Basics, Syntax & Well-Formedness
<window height="50" width="50"/>
-
Write XML code to create two elements.
Topic: XML Basics, Syntax & Well-Formedness
<name>Ali</name> <city>Lahore</city>
-
Name any three building blocks of an XML document.
Topic: XML Basics, Syntax & Well-Formedness
1. Elements 2. Attributes 3. Entities (Other valid answers: PCDATA, CDATA.)
-
What is a valid XML document?
Topic: XML Basics, Syntax & Well-Formedness
A valid XML document is a well-formed XML document (it follows all the syntax rules of XML) that also conforms to the rules of a DTD associated with it — that is, it uses only the elements and attributes declared in the DTD, in the structure the DTD allows. A document that is only well-formed but does not follow any DTD is not called valid.
-
What is an XML tree? Explain briefly.
Topic: XML Tree, DTD & Entities
An XML tree starts with a root element, and all other elements are its child nodes. root ■■■ child ■■■ subchild
-
Write the XML code/document for the tree (diagram) given in the paper.
Topic: XML Tree, DTD & Entities • 5 Marks marks
Method: if a tree is given in the exam, the XML code is written by starting from the root element and nesting the child elements inside their parent elements, closing every tag. The exact code depends on the diagram given in the paper. Worked example — for a tree whose root is "company", with a child "employee" containing the text "Ali", the XML document is: <company> <employee>Ali</employee> </company>
-
Define the entity references used for the characters <, > and & in XML.
Topic: XML Tree, DTD & Entities • 3 Marks marks
The characters <, > and & have a special meaning in XML, so they cannot be written directly in the content; they are written using predefined entity references, which act as replacement text (shortcuts) for these special characters: < is the entity reference for < (less than) > is the entity reference for > (greater than) & is the entity reference for & (ampersand) Two more predefined entity references in XML are ' for ' (apostrophe) and " for " (quotation mark).
-
Write the syntax of an external entity.
Topic: XML Tree, DTD & Entities
<!ENTITY company SYSTEM "company.xml"> or <!ENTITY name SYSTEM "data.txt">
-
Write an XML document using the given DTD. (The DTD declares a "note" element containing firstname, lastname and email, each declared as #PCDATA.)
Topic: XML Tree, DTD & Entities
<?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (firstname, lastname, email)> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname (#PCDATA)> <!ELEMENT email (#PCDATA)> ]> <note> <firstname>Ali</firstname> <lastname>Ahmad</lastname> <email>ali@gmail.com</email> </note> The same task with a different DTD (note containing to, from, body) has the document: <note> <to>Ali</to> <from>Ahmed</from> <body>Hello</body> </note>
-
Write a DTD for the given XML code.
Topic: XML Tree, DTD & Entities
General format: <!DOCTYPE note [ <!ELEMENT note (to,from,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> Worked example — if the XML code given is: <note> <to>Ali</to> <from>Ahmed</from> </note> then the DTD is: <!ELEMENT note (to,from)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> (The exact DTD depends on the XML code given in the paper.)
-
Write a DTD program for a simple XML document of a company containing employees.
Topic: XML Tree, DTD & Entities
For a simple XML of company/employees, the handout-style DTD is usually: <!DOCTYPE company [ <!ELEMENT company (employee)> <!ELEMENT employee (#PCDATA)> ]> (The exact DTD depends on the XML code given in the paper.)
-
Write the XML document (company program) for the given DTD/structure.
Topic: XML Tree, DTD & Entities
If a DTD was given and XML was required, the document is: <company> <employee>Ali</employee> </company> (The exact answer depends on the company structure provided in the paper.)
-
List the DOM node types along with their numerical values.
Topic: XML DOM — Node Types, Properties, Traversing & Node Access
Element Node = 1 Attribute Node = 2 Text Node = 3 Comment Node = 8 Document Node = 9
-
List the common properties of the XML DOM (nodes).
Topic: XML DOM — Node Types, Properties, Traversing & Node Access
nodeName, nodeValue, nodeType, parentNode, childNodes, firstChild, lastChild, nextSibling, previousSibling, attributes.
-
Define traversing.
Topic: XML DOM — Node Types, Properties, Traversing & Node Access
Traversing is the process of moving through the nodes of an XML document tree to access, search, or manipulate data.
-
How many ways are there to access a node in the XML DOM? Name them.
Topic: XML DOM — Node Types, Properties, Traversing & Node Access
There are three ways: 1. getElementById() 2. getElementsByTagName() 3. getElementsByName() These methods are used to access nodes/elements in an XML document.
-
Convert the following XML code into an XML DOM (tree) representation: <company> <employee>Ali</employee> </company>
Topic: XML DOM — Node Types, Properties, Traversing & Node Access
DOM tree: company ■■■ employee ■■■ Ali Or in DOM terms: Document Node – Element Node (company) – Element Node (employee) – Text Node (Ali)
-
Write the code to remove the "age" attribute of the fifth teacher element.
Topic: XML DOM Programming (JavaScript) • 3 Marks marks
xmlDoc = loadXMLData("staff.xml"); x = xmlDoc.getElementsByTagName("teacher"); x[4].removeAttribute("age");
-
Write the code to replace the data of the first element with "Right Handed Bowler".
Topic: XML DOM Programming (JavaScript) • 5 Marks marks
xmlDoc = loadXMLData("team.xml"); x = xmlDoc.getElementsByTagName("Style"); x[0].childNodes[0].nodeValue = "Right Handed Bowler";
-
(i) Create an element "bowler". (ii) Create an attribute "age" and set its value to 35.
Topic: XML DOM Programming (JavaScript) • 5 Marks marks
var elem = xmlDoc.createElement("bowler"); var att = xmlDoc.createAttribute("age"); att.value = "35"; elem.setAttributeNode(att); xmlDoc.documentElement.appendChild(elem); createElement() creates the new element node, createAttribute() creates the new attribute, its value is set to 35, and setAttributeNode() attaches the attribute to the element.
-
List the values of the readyState property (0–4) of the XMLHttpRequest object and state the purpose of each value.
Topic: AJAX & the XMLHttpRequest Object
0 — Request not initialized 1 — Server connection established 2 — Request received 3 — Processing request 4 — Request finished and response is ready During a server request, the readyState changes from 0 to 4.
-
What do the HTTP status codes 200 and 404 mean?
Topic: AJAX & the XMLHttpRequest Object
200 OK — the request was successful. 404 Not Found — the requested resource/page was not found.
-
In XML (AJAX), the open() function/method has 3 arguments. Define each argument, its value and its usage.
Topic: AJAX & the XMLHttpRequest Object • 3 Marks marks
The XMLHttpRequest open() method is written as open(method, url, async): 1. method — the type of request: GET or POST. It specifies how the data is sent to the server. 2. url — the address (location) of the file on the server to which the request is sent. 3. async — true or false. true means the request is handled asynchronously (the script continues without waiting for the server response); false means it is handled synchronously.
-
How can the problem of name conflicts in XML be solved?
Topic: XML Namespaces
XML Namespaces are used to solve name conflicts. A namespace prefix, declared with the xmlns attribute, makes element names unique. Example: <h:table xmlns:h="http://www.w3.org/TR/html4/"> <f:table xmlns:f="https://www.w3schools.com/furniture"> Here the two elements named "table" belong to different namespaces (prefixes h and f), so there is no conflict.
-
Write the complete syntax of the service() method.
Topic: Web Services, Servlets, JAX-WS & JDOM • 3 Marks marks
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
-
How many ways are there to represent JAX-WS? Name them.
Topic: Web Services, Servlets, JAX-WS & JDOM • 3 Marks marks
There are two ways to represent JAX-WS: 1. Bottom-Up Approach 2. Top-Down Approach
-
Write JDOM API Java code to: (i) extract the root element; (ii) extract any specified attribute of the root element.
Topic: Web Services, Servlets, JAX-WS & JDOM • 3 Marks marks
(i) Extract the root element: Element root = doc.getRootElement(); (ii) Extract any specified attribute of the root element: Attribute attr = root.getAttribute("attributeName");
-
Name the five most common JDOM classes.
Topic: Web Services, Servlets, JAX-WS & JDOM • 5 Marks marks
1. Document 2. Element 3. Attribute 4. Text 5. Comment
-
Explain the roles in Web Services architecture.
Topic: Web Services, Servlets, JAX-WS & JDOM • 5 Marks marks
There are three roles: 1. Service Provider — creates and publishes the web service. 2. Service Requester — finds and uses the web service. 3. Service Registry — stores information about available web services and helps requesters discover them.
-
Create an XML document of the following, where "......." means more cities which are saved in a PHP array $cities: <?xml version="1.0" encoding="UTF-8" ?> <country> <city>lahore</city><city>islamabad</city> ....... </country>
Topic: XML with PHP & XHTML • 5 Marks marks
In PHP, the fixed cities are written directly and the remaining cities are printed from the $cities array using a loop: <?php $cities = array("Karachi", "Multan", "Faisalabad"); echo "<country>"; echo "<city>lahore</city>"; echo "<city>islamabad</city>"; foreach ($cities as $city) { echo "<city>$city</city>"; } echo "</country>"; ?> This generates one <city> element for every city stored in the array, inside the <country> root element.
-
Differentiate between XML and XHTML.
Topic: XML with PHP & XHTML
XML (eXtensible Markup Language) is a markup language designed to store and transport data; it describes the data itself and lets the user define his/her own tags. XHTML (eXtensible HyperText Markup Language) is HTML rewritten according to the rules of XML; it is used to display data and has a fixed set of predefined tags. XHTML is stricter than HTML: all elements must be properly closed, properly nested and written in lower case, attribute values must be quoted, and the document must have a single root element — because it must be a well-formed XML document.
-
Differentiate between SAX and DOM parsers.
Topic: Additional Important Subjective Questions
SAX (Simple API for XML) is an event-based parser: it reads the document sequentially from start to end and reports events (start of element, end of element, character data, etc.) to the application. It does not load the whole document into memory, so it is fast and uses very little memory, but it gives only sequential, read-only access. DOM (Document Object Model) is a tree-based parser: it loads the whole XML document into memory as a tree of nodes. It allows random access, navigation and modification of the document, but it uses more memory and is slower for very large documents.
-
An XML document to be processed is very large, and the application extracts only a small portion of the information from it. Memory and speed are constraints. Which parsing approach — SAX or DOM — is most appropriate, and why?
Topic: Additional Important Subjective Questions
SAX is the most appropriate approach. Because SAX processes the document sequentially as a stream of events and never builds the whole tree in memory, it is fast and memory-efficient for very large documents, especially when only a small portion of the data is needed and the document does not have to be modified. DOM would load the entire document into memory, which is wasteful under memory and speed constraints.
-
What is XSLT? What is it used for?
Topic: Additional Important Subjective Questions
XSLT (eXtensible Stylesheet Language Transformations) is a language/part of XSL used to transform an XML document into another XML document, or into another format such as HTML. The transformation is defined in a stylesheet, and an XSLT processor applies it to the source XML document to produce the result document.
-
Differentiate between CDATA and PCDATA.
Topic: Additional Important Subjective Questions
PCDATA (Parsed Character Data) is text data that will be parsed by the XML parser — any tags or entity references inside it are recognised and processed. CDATA (Character Data) is text data that should NOT be parsed by the XML parser. It is written inside a <![CDATA[ ... ]]> section, so characters such as < and & inside it are treated as ordinary characters and ignored by the parser.
-
Differentiate between an internal DTD and an external DTD (internal subset vs external subset).
Topic: Additional Important Subjective Questions
An internal DTD (internal subset) is declared inside the XML document itself, wrapped in the DOCTYPE declaration: <!DOCTYPE root-element [ ...declarations... ]>. An external DTD (external subset) is written in a separate file, and the XML document only points to it from its DOCTYPE declaration. When the DTD is pointing to an external file/path, it is called an external subset.
-
Differentiate between a well-formed XML document and a valid XML document.
Topic: Additional Important Subjective Questions
A well-formed XML document follows all the syntax rules of XML: it has a single root element, every opening tag has a closing tag, elements are properly nested, tags are case-sensitive and attribute values are quoted. A valid XML document is a well-formed document that also conforms to a DTD (or schema) — its elements, attributes and structure match the declarations. Every valid document is well-formed, but a well-formed document is not necessarily valid.
-
What is XPath? What is it used for?
Topic: Additional Important Subjective Questions
XPath is an expression language used to navigate through the elements and attributes of an XML document and to find/select information (nodes) in it. It uses path expressions, similar to file paths, to identify parts of an XML document.
-
How are attributes declared in a DTD? Write the general syntax and explain #REQUIRED and #IMPLIED.
Topic: Additional Important Subjective Questions
Attributes are declared in a DTD with an ATTLIST declaration: <!ATTLIST element-name attribute-name attribute-type default-value> #REQUIRED means the attribute must be present — if there is no option for a default value but the attribute must still be forced to appear, the #REQUIRED keyword is used. #IMPLIED means the attribute is optional — it has no default value and is not required to be present.