Cs311 Midterm File
Cs311 Midterm File
1. What is XML?
o a) A programming language
o b) A markup language
o c) A database
o d) A compiler
Answer: b) A markup language
2. Which attribute is used to define the version of an XML document?
o a) xmlversion
o b) version
o c) encoding
o d) docversion
Answer: b) version
3. What is the root of an XML document called?
o a) Header
o b) Body
o c) Root element
o d) Attribute
Answer: c) Root element
4. Which of the following statements about XML is correct?
o a) XML tags are predefined.
o b) XML tags are user-defined.
o c) XML is case-insensitive.
o d) XML does not allow attributes.
Answer: b) XML tags are user-defined.
5. What does the "DOM" in XML DOM stand for?
o a) Document Object Model
o b) Data Organization Model
o c) Document Optimization Model
o d) Data Object Management
Answer: a) Document Object Model
6. What type of structure does XML DOM represent?
o a) Linear
o b) Tree
o c) Circular
o d) Graph
Answer: b) Tree
7. Which method in the XML DOM is used to retrieve an element by its ID?
o a) getElementById
o b) getNodeById
o c) querySelector
o d) getElementByName
Answer: a) getElementById
8. What does a "node" represent in the XML DOM?
o a) A single character in the XML document
o b) An individual part of the XML tree
o c) A root element
o d) A namespace
Answer: b) An individual part of the XML tree
9. What is a child node in XML DOM?
o a) The root node
o b) A node that is directly connected to a parent node
o c) The last node in the tree
o d) An attribute of the root
Answer: b) A node that is directly connected to a parent node
10. Which method is used to create a new element in XML DOM?
o a) createElement
o b) newElement
o c) addElement
o d) generateElement
Answer: a) createElement
11. How do you add a new child node to an XML document in DOM?
o a) appendChild
o b) addNode
o c) insertNode
o d) pushChild
Answer: a) appendChild
12. Which of these is an XML DOM property?
o a) nodeName
o b) addElement
o c) createNode
o d) elementType
Answer: a) nodeName
13. What is the purpose of the getElementsByTagName method in DOM?
o a) To retrieve elements by their tag name
o b) To delete elements by their tag name
o c) To rename elements in the document
o d) To replace elements by their tag name
Answer: a) To retrieve elements by their tag name
14. Which of these methods can be used to remove a node in the DOM?
o a) removeChild
o b) deleteNode
o c) dropElement
o d) removeElement
Answer: a) removeChild
15. What does the nodeType property in XML DOM specify?
o a) The parent of the node
o b) The type of the node
o c) The attributes of the node
o d) The child nodes of the node
Answer: b) The type of the node
21. Which method in the DOM is used to find a node based on its name?
o a) getNodeByName
o b) getElementsByTagName
o c) findNode
o d) querySelectorAll
Answer: b) getElementsByTagName
22. What does the parentNode property in XML DOM return?
o a) The root node
o b) The parent node of the selected node
o c) The first sibling of the node
o d) The first child of the parent node
Answer: b) The parent node of the selected node
23. Which property of the DOM node contains the actual data?
o a) nodeValue
o b) dataContent
o c) innerText
o d) textContent
Answer: a) nodeValue
24. What is the hasChildNodes method used for in the XML DOM?
o a) To check if a node has any attributes
o b) To check if a node has any child nodes
o c) To check if a node has a parent
o d) To check if a node has siblings
Answer: b) To check if a node has any child nodes
25. Which method can clone a node in the XML DOM?
o a) cloneNode
o b) copyNode
o c) duplicateNode
o d) createClone
Answer: a) cloneNode
26. What is the output of document.documentElement in the XML DOM?
o a) The first element in the document
o b) The root element of the document
o c) The last element in the document
o d) The first child of the root element
Answer: b) The root element of the document
27. Which method is used to normalize the text content of a node in the XML DOM?
o a) normalize
o b) formatText
o c) normalizeContent
o d) textNormalize
Answer: a) normalize
28. Which of the following is NOT a node type in the XML DOM?
o a) ELEMENT_NODE
o b) ATTRIBUTE_NODE
o c) STYLE_NODE
o d) TEXT_NODE
Answer: c) STYLE_NODE
29. What is a CDATA section in XML?
o a) A section where data is compressed
o b) A section where data is ignored by the parser
o c) A section where character data is not parsed by the parser
o d) A section for defining comments
Answer: c) A section where character data is not parsed by the parser
30. How are comments defined in an XML document?
o a) <!-- Comment -->
o b) // Comment
o c) /* Comment */
o d) # Comment
Answer: a) <!-- Comment -->
31. What is the use of namespaces in XML?
o a) To avoid element name conflicts
o b) To define document encoding
o c) To organize attributes
o d) To structure data hierarchically
Answer: a) To avoid element name conflicts
32. Which prefix is used for namespaces in XML?
o a) ns
o b) xmlns
o c) xml
o d) namespace
Answer: b) xmlns
33. What does the localName property return in XML DOM?
o a) The name of the local file
o b) The local part of the element's name
o c) The namespace of the element
o d) The full name of the element
Answer: b) The local part of the element's name
34. What is an attribute in XML?
o a) A special type of node that provides additional information about an
element
o b) A child node of an element
o c) The root element of an XML document
o d) A property of the document type
Answer: a) A special type of node that provides additional information about
an element
35. Which of the following methods can be used to select nodes in an XML
document?
o a) XPath
o b) CSS selectors
o c) Query API
o d) Node.js
Answer: a) XPath
36. What does textContent in XML DOM represent?
o a) The textual content of a node and all its descendants
o b) Only the text of the root node
o c) The tag names of all child nodes
o d) The name of the document
Answer: a) The textual content of a node and all its descendants
37. Which of the following XML parsers works event-based?
o a) DOM
o b) SAX
o c) StAX
o d) Schema Validator
Answer: b) SAX
38. What is the primary advantage of SAX parsing over DOM parsing?
o a) It is faster and requires less memory
o b) It provides a visual interface for XML documents
o c) It automatically validates XML documents
o d) It supports namespaces by default
Answer: a) It is faster and requires less memory
39. What does nodeList.length return in XML DOM?
o a) The number of elements in a node
o b) The number of child nodes in a node
o c) The length of the textual content of a node
o d) The number of attributes in a node
Answer: b) The number of child nodes in a node
40. What is the purpose of innerHTML in XML DOM?
o a) To get or set the content of an element, including tags
o b) To fetch the textual content only
o c) To set the namespace of an element
o d) To define the schema
Answer: a) To get or set the content of an element, including tags
• a) hasAttributes()
• b) checkAttributes()
• c) getAttributes()
• d) validateAttributes()
Answer: a) hasAttributes()
• Which property is used to retrieve all child nodes of a given node in XML DOM?
• a) childNodes
• b) nodeChildren
• c) children
• d) getChildNodes()
Answer: a) childNodes
• a) getAttributeNode()
• b) retrieveAttribute()
• c) attributeNode()
• d) fetchAttribute()
Answer: a) getAttributeNode()
• Which method is used to remove a child node from the parent node?
• a) removeChild()
• b) deleteNode()
• c) eraseChild()
• d) clearNode()
Answer: a) removeChild()
• What does the nodeType property of a DOM node return?
• a) An error
• b) null
• c) An empty string
• d) A default value
Answer: b) null
• a) COMMENT_NODE
• b) ATTRIBUTE_TYPE
• c) STYLE_NODE
• d) ELEMENT_TYPE
Answer: a) COMMENT_NODE
• Which method is used to replace an existing node with a new node in XML DOM?
• a) replaceChild()
• b) swapNode()
• c) updateChild()
• d) changeNode()
Answer: a) replaceChild()
• a) getElementsByTagNameNS()
• b) querySelector()
• c) getNodesByNamespace()
• d) selectByNamespace()
Answer: a) getElementsByTagNameNS()
• a) attributes
• b) getAttributes
• c) attributeList
• d) nodeAttributes
Answer: a) attributes
• a) getElementById()
• b) getElementsByTagName()
• c) setElementType()
• d) createElement()
Answer: c) setElementType()
• Which property is used to access the first sibling of a node in XML DOM?
• a) firstSibling
• b) previousSibling
• c) parentNode
• d) nextSibling
Answer: b) previousSibling
• a) 1
• b) 2
• c) 3
• d) 4
Answer: a) 1
• What does document.createAttribute() do in XML DOM?
• Which method removes all child nodes from a parent node in XML DOM?
• a) removeChildNodes()
• b) clearChildren()
• c) removeAllChildren()
• d) There is no direct method; it must be done manually
Answer: d) There is no direct method; it must be done manually
• a) getNodeByNameNS()
• b) getElementsByTagNameNS()
• c) querySelectorNS()
• d) selectByNamespace()
Answer: b) getElementsByTagNameNS()
• a) nodeType
• b) childType
• c) childNodes
• d) nodeChildrenType
Answer: a) nodeType
• a) removeAttributeNode()
• b) deleteAttribute()
• c) clearAttribute()
• d) removeNode()
Answer: a) removeAttributeNode()
• a) nodeName
• b) nodeType
• c) nodeValue
• d) nodeContent
Answer: a) nodeName
• a) parentNode
• b) nodeChildren
• c) childNodes
• d) firstChild
Answer: b) nodeChildren
• What is the purpose of getElementsByClassName() in XML DOM?
• a) 1
• b) 2
• c) 3
• d) 4
Answer: c) 3
• Which property in XML DOM provides access to the last child node?
• a) lastChild
• b) endNode
• c) tailNode
• d) finalChild
Answer: a) lastChild
• a) length
• b) content
• c) attributes
• d) nodeList
Answer: a) length
• What does the document.createTextNode() method do?
• a) nodeName
• b) tagName
• c) elementName
• d) name
Answer: a) nodeName
• a) removeAttribute()
• b) deleteAttribute()
• c) clearAttribute()
• d) removeNodeAttribute()
Answer: a) removeAttribute()
• a) childNodes includes all node types, children only includes element nodes
• b) children includes all node types, childNodes only includes element nodes
• c) Both are identical
• d) children is used for attributes, childNodes is used for elements
Answer: a) childNodes includes all node types, children only includes element
nodes
• Which method is used to check if a node has any child nodes?
• a) hasChildNodes()
• b) checkChildNodes()
• c) getChildNodes()
• d) validateChildren()
Answer: a) hasChildNodes()