Chapter 24 Exam Questions XML - Big Java Early Objects 5e Complete Test Bank by Cay S. Horstmann. DOCX document preview.
Course Title: Big Java, Early Objects
Chapter Number: 24 XML
Question type: Multiple Choice
1) ____________ is an extensible syntax that can be used to specify many different kinds of data.
a) DOM
b) ELEMENT
c) XHTML
d) XML
Title: ___ is an extensible syntax for specifying many kinds of data.
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
2) In XML, an attribute has a name and a(n) ____________________.
a) variable
b) element
c) value
d) object
Title: An XML attribute has a name and a ___.
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
3) Which of the following statements is correct?
a) XML is an extensible syntax that can be used to specify many different kinds of data.
b) XML has one specific purpose: to describe web documents.
c) XML tells you how to display data.
d) You can always replace XML elements with attributes.
Title: Which of these statements about XML is correct?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
4) Which of the following statements is correct?
a) XML-formatted data files are resilient to change.
b) In XML, start-tags need not have matching end-tags.
c) XML describes how to display data.
d) HTML is a special case of XML.
Title: Which of these statements about XML is correct?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
5) Which of the following statements is correct?
a) In XML, every start-tag must have a matching end-tag.
b) XML files are readable by computer programs but not by humans.
c) Attribute values need not be enclosed in quotes.
d) An element cannot contain mixed content.
Title: Which of these statements about XML is correct?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
6) Which of the following statements is correct?
a) Elements cannot have attributes.
b) An XML document starts out with an HTML declaration and contains elements and text.
c) An element must contain text or elements, not both.
d) An attribute is appropriate only if it tells something about the data but is not part of the data itself.
Title: Which of these statements about XML is correct?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
7) One of the advantages of XML is that _________.
a) it is resilient to change.
b) it is difficult to understand.
c) its values don’t have to be enclosed in quotes.
d) array positions start with 1.
Title: What are the advantages of XML?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
8) Which of the following statements is correct?
a) Elements describe how to interpret attributes.
b) In XML, attribute values must be enclosed in quotes.
c) Mixed content allows you to have control over the order in which elements appear.
d) You should always use mixed content for elements that describe data sets.
Title: Which of these statements about XML is correct?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
9) Which of the following XML fragments contains an error?
a) <name lang="en">half dollar</name>
b) <img src="hamster.jpeg"/>
c) <img src="hamster.jpeg" width=400 height=300/>
d) <name lang="germ">quarter</name>
Title: Which of the following XML fragments contains an error?
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
10) The XML standard recommends that every XML document start with ____.
a) <xml version="1.0"?>
b) <?xml version="1.0"?>
c) <xml version="1.0">
d) <?xml version="1.0">
Title: Every XML document should start with ____.
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
11) Write an XML fragment with a course element and two child elements, courseID and credits. The course ID is CS605 and it has 3 credit hours.
a)
<course>
<courseID> CS605 </courseID>
<credits> 3 </credits>
</course>
b)
<course>
<courseID> CS605
<credits> 3 </credits>
</courseID>
</course>
c)
<courseID>
<course> CS605 </course>
<credits> 3 </credits>
</courseID>
d)
<course>
<courseID> CS605 </courseID>
</course>
<course>
<credits> 3 </credits>
</course>
Title: XML fragment for describing course.
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
12) An XPath describes a node or_______, using a syntax that is similar to directory paths.
a) folder
b) set of nodes
c) parser
d) model
Title: An XPath describes a node or ___.
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
13) A ___________ is a program that reads a document, checks whether it is syntactically correct, and takes some action as it processes the document.
a) browser
b) compiler
c) document builder
d) parser
Title: A ___ is a program that reads an XML document...
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
14) A ________ parser reports the building blocks of an XML document.
a) tree-based
b) XPath
c) streaming
d) DOM
Title: A ___ parser reports the building blocks of an XML document.
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
15) To generate an object of a class that implements the Document interface, you need a __________.
a) DocumentGenerator
b) DocumentBuilder
c) DocumentValidator
d) ObjectBuilder
Title: To generate a Document object, you need a ___.
Difficulty: Easy
Section Reference 1: 24.3 Creating XML Documents
16) A __________ parser builds a document tree.
a) streaming
b) DOM
c) DTD
d) Document Model Object
Title: A ___ parser builds a document tree.
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
17) To read and analyze the contents of an XML document, you need an XML ____________.
a) parser
b) document analyzer
c) path
d) tokenizer
Title: To read an XML document, you need an XML ___.
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
18) The ____ standard defines interfaces and methods to analyze and modify the tree structure that represents an XML document.
a) JAXP
b) SAX
c) DOM
d) API
Title: The ___ standard describes a tree structure for XML documents.
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
19) To get a DocumentBuilder object, first call the static ____ method of the DocumentBuilderFactory class.
a) newInstance
b) document
c) connection
d) newDocument
Title: You call the ___ method to get a DocumentBuilder object.
Difficulty: Easy
Section Reference 1: 24.3 Creating XML Documents
20) Which of the following attribute types describes any sequence of character in a DTD?
a) #REQUIRED
b) #IMPLIED
c) CDATA
d) ATTLIST
Title: Which of these describes any sequence of character data?
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
21) A ____________ is a sequence of rules that describes the valid attributes for each element and the valid child elements for each element type.
a) DOM
b) Protocol
c) DTD
d) Data Definition Type
Title: A ___ is a sequence of rules for valid attributes and elements.
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
22) In XML, ___________ refers to any sequence of character data and elements.
a) ASCII characters
b) EBCIDC
c) mixed elements
d) mixed content
Title: ___ refers to any sequence of character data and elements.
Difficulty: Easy
Section Reference 1: 24.1 XML Tags and Documents
23) Which of the following represents the declaration of a DTD contained within the XML document?
a) <!ELEMENT rootElement [ rules ]>
b) <!DOCTYPE rootElement [ rules ]>
c) <!DTD rootElement [ rules ]>
d) <!REQUIRED rootElement [ rules ]>
Title: Which of these represents the declaration of a DTD?
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
24) When referencing an external DTD (one not on the current file system), you must supply a(n) ____ for locating the DTD.
a) URL
b) domain name
c) IP address
d) element
Title: You must supply a ____ for locating an external DTD.
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
25) In XML, a DTD is introduced with the ___________ declaration.
a) FIXED
b) REQUIRED
c) IMPLIED
d) DOCTYPE
Title: A DTD is introduced with the ___ declaration.
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
26) The inclusion of a DTD in an XML document allows you tell the parser to validate the document. The ___________ method of the DocumentBuilderFactory class allows you to turn on validation.
a) setValidator
b) setValidating
c) documentBuilder
d) setFactory
Title: The ___ method allows you to turn on validation.
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
27) To make the parser ignore white space between elements, you should call the __________ method of the DocumentBuilderFactory class.
a) setIgnoringElementContentWhitespace
b) setElementContentWhitespace
c) setIgnoringContentWhitespace
d) setIgnoringElementContent
Title: Call the ___ method to ignore white space.
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
28) How can a DTD specify that a course child element in a semester element is optional?
a) <!ELEMENT semester (class?, course)>
b) <!ELEMENT semester (class, course) />
c) <!ELEMENT semester (class, course?)>
d) <!ELEMENT semester (class, course*)>
Title: How can a DTD specify that an element is optional?
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
29) A _____________ reads and reports on each element of an XML document as it reads it.
a) DOM parser
b) tree-based parser
c) block parser
d) streaming parser
Title: A _____ reads and reports on each element of an XML document.
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
30) Which parser gives you an overview of the complete document so you can analyze it?
a) grammar parser
b) tree-based parser
c) block parser
d) streaming parser
Title: Which parser gives you an overview of the complete document so you can analyze it?
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
31) What does DOM stand for?
a) Data Object Model
b) Data Oriented Model
c) Document Object Model
d) Definition Object Model
Title: What does DOM stand for?
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
32) When converting an XML document to Java classes, how should you think about XML elements?
a) Elements are equivalent to classes.
b) Elements are like instance variables.
c) Elements are similar to superclasses.
d) Elements can be instance variables, classes, or methods.
Title: When converting XML to Java, how should you think about XML elements?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
33) Where is the newDocumentBuilder method?
a) In the DocumentBuilder class.
b) In the DocumentFactoryBuilder class.
c) In the DocumentFactory class.
d) In the DocumentBuilderFactory class.
Title: Where is the newBuilder method?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
34) Given the following code, what will the XPath /items/item[2]/quantity select?
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) 19.95
b) 4
c) 8
d) The element does not exist.
Title: What does the XPath select?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
35) Given the following code, what will the XPath /items/item[0]/quantity select?
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) 19.95
b) 4
c) 8
d) The element does not exist.
Title: What does the XPath select?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
36) Given the following code, what will the XPath count(/items/item) generate?
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) 1
b) 2
c) 3
d) 4
Title: What does the XPath output?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
37) Given the following code, what will the XPath name(/items/item[2]/*[2]) generate?
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) price
b) product
c) description
d) quantity
Title: What does the XPath output?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
38) Given the following code, what will the XPath /items/item[2]/product/price generate?
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) 29.95
b) 19.95
c) 2
d) 4
Title: What does the XPath output?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
39) Given the following code, what will the XPath count(/items/*) generate?
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) 1
b) 2
c) 3
d) 4
Title: What does the XPath output?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
40) Assuming that path is properly instantiated object of type XPath and doc is the document below, what is the value of result in the statement
String result = path.evaluate("count(/items/*", doc);
<items>
<item>
<product>
<description>Ink Jet Refill Kit</description>
<price>29.95</price>
</product>
<quantity>8</quantity>
</item>
<item>
<product>
<description>4-port Mini Hub</description>
<price>19.95</price>
</product>
<quantity>4</quantity>
</item>
</items>
a) 1
b) 2
c) 3
d) 4
Title: What is the output of the following code?
Difficulty: Medium
Section Reference 1: 24.2 Parsing XML Documents
41) What kind of object do you need to create a new, empty XML document?
a) DocumentBuilder
b) newBuilder
c) newInstance
d) newDocumentBuilder
Title: What kind of object do you need to create a new, empty XML document?
Difficulty: Easy
Section Reference 1: 24.3 Creating XML Documents
42) The package javax.xml.parsers contains:
a) Element and Text
b) Document and DocumentBuilder
c) DocumentBuilder and DocumentBuilderFactory
d) Element and Document
Title: The package javax.xml.parsers contains:
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
43) What kind of object do you need to read an XML document?
a) DocumentBuilder
b) newBuilder
c) newInstance
d) newDocumentBuilder
Title: What kind of object do you need to read in an XML document?
Difficulty: Easy
Section Reference 1: 24.2 Parsing XML Documents
44) What method do you use to insert a node into an XML document?
a) insertNode method.
b) createNode method.
c) createElement method.
d) insertElement method.
Title: What method do you use to insert node into an XML document?
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
45) Where is the createElement method located?
a) DocumentBuilder class.
b) newBuilder class.
c) DocumentBuilder interface.
d) Document interface.
Title: Where is the createElement method located?
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
46) You set element attributes with the _________method.
a) setElementAttributes
b) setElement
c) setAttributes
d) setAttribute
Title: You set element attributes with the _________method.
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
47) To insert text, you need the _________methods.
a) insertElement and setElement
b) createNode and insertChild
c) createTextNode and appendChild
d) insertTextNode and insertChild
Title: To insert text, you need the _________methods.
Difficulty: Hard
Section Reference 1: 24.3 Creating XML Documents
48) To write a DOM document, you need to use an object that implements the _________ interface.
a) DocumentBuilder
b) Serializable
c) Serializer
d) LSSerializer
Title: To write a DOM document, you need to use a _________ interface.
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
49) The XML encoding for the “>” character is:
a) &gr;
b) &greaterThan;
c) >
d) <
Title: The XML encoding for “>” character is:
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
50) The XML encoding & is the replacement for the ____ character.
a) @
b) !
c) %
d) &
Title: The XML encoding & is the replacement for the ____character.
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
51) An element that is declared as _______ in a DTD may not have any children.
a) PCDATA
b) ELEMENT
c) NULL
d) EMPTY
Title: An element that is declared as _______ may not have any children.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
52) An EMPTY element is:
a) an element that may have zero or more children.
b) an element that has no value.
c) an element whose value is the null string.
d) an element that may not have any children.
Title: An EMPTY element is:
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
53) Given the following DTD expression, which section element is valid?
<!ELEMENT section (title, (paragraph | (image, title?))+)>
a)
<section>
<title/>
<paragraph/>
<image/>
<title/>
<paragraph/>
</section>
b)
<section>
<paragraph/>
<paragraph/>
<title/>
</section>
c)
<section>
<paragraph/>
<title/>
<title/>
<paragraph/>
</section>
d)
<section>
<paragraph/>
<image/>
<title/>
<paragraph/>
</section>
Title: Given the following DTD expression, which element is valid?
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
54) The #PCDATA rule means ____________.
a) the children can consist of any numeric data.
b) the children can consist of 0 or more elements.
c) the children can consist of any character data.
d) any children allowed.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
55) Mixed content is ____________.
a) any sequence of numeric data and character data.
b) any sequence of character data followed by character data.
c) any sequence of character data and specified elements.
d) any sequence of numeric data and specified elements.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
56) In an attribute definition in a DTD, a #REQUIRED declaration means ____________.
a) the attribute is valid.
b) the attribute is required.
c) the attribute is optional.
d) the attribute is implied.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
57) In an attribute definition in a DTD, an #IMPLIED declaration means ____________.
a) the attribute is valid.
b) the attribute is required.
c) the attribute is optional.
d) the attribute is implied.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
58) In an attribute definition in a DTD, a #FIXED V declaration means ____________.
a) the attribute must be either unspecified or contain V.
b) the attribute is unspecified.
c) the attribute is optional.
d) the attribute is required.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
59) In an attribute definition in a DTD, a V declaration means ____________.
a) use the value V or a value that contains V.
b) use the value V if the attribute is unspecified.
c) use the value V if the attribute is optional.
d) use the value V if the attribute is required.
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
60) When referencing an external DTD (one not on the current file system), you must ____________.
a) supply a DOCTYPE.
b) supply a URL.
c) supply both DOCTYPE and URL.
d) use the SYSTEM reserved word.
Title: When referencing an external DTD you must:
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
61) When you parse an XML file with a DTD, ____________.
a) you should tell the parser to ignore the white space.
b) you don’t need to request validation.
c) you should supply URL for locating the DTD.
d) your should tell the parser to convert all white space to text.
Title: When you parse an XML file with a DTD:
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
62) What is one reason to have the DOM parser ignore white space in an XML document?
a) White space may make the element names invalid.
b) The parser will otherwise make unneeded nodes of the white space.
c) The parser will otherwise add white space to the elements.
d) White space cannot be streamed.
Title: Why have the parser ignore white space?
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
63) The method setIgnoringElementContentWhitespace is in the _____ class:
a) DocumentDataDefinition
b) DocumentFactory
c) DocumentFactoryBuilder
d) DocumentBuilderFactory
Title: The method setIgnoringElementContentWhitespace is in the _____ class:
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
64) For elements that contain text, the DTD rule is:
a) <!ELEMENT name (#FIXED "STATE")>
b) <!ELEMENT name (#PCDATA)>
c) <!ELEMENT name (#IMPLIED)>
d) <!ELEMENT name ("STATE")>
Title: For elements that contain text, the DTD rule is:
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
65) For price elements that must contain currency, the attribute list is:
a) <!ATTLIST price currency CDATA #REQUIRED>
b) <!ATTLIST price currency CDATA "USD">
c) <!ATTLIST price currency #REQUIRED "USD">
d) <!ATTLIST price #REQUIRED "USD">
Title: For price elements that must contain currency, the attribute list is:
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
Section Reference 2: How To 24.3
66) Which definition in an XML schema restricts the contents of quantity to an integer?
a) <xsd:element name="quantity" type="integer"/>
b) <xsd:element name="quantity" type="xsd:string" />
c) <xsd:element name="quantity" type="integer:xsd" />
d) <xsd:element name="quantity" type="xsd:integer" />
Title: Which definition restricts the contents of quantity to an integer?
Difficulty: Medium
Section Reference 1: 24.4 Validating XML Documents
Section Reference 2: Special Topic 24.1
67) A number of useful advanced XML technologies have been standardized. Among them is:
a) HTML
b) HXML
c) XHTML
d) W3C
Title: One useful advanced XML technology is:
Difficulty: Easy
Section Reference 1: 24.4 Validating XML Documents
Section Reference 2: Special Topic 24.2
a) “article must be equal to a”
b) “article can be replaced with a or not a”
c) “article can be replaced with a”
d) “article cannot be equal to”
Title: In a grammar, what does <article> ::= a mean?
Difficulty: Easy
Section Reference 1: 24.3 Creating XML Documents
a) “article must be equal to a and the”
b) “article can be replaced with a or the”
c) “article can be replaced with a and the”
d) “article cannot be equal a or the”
Title: In a grammar, what does <article> ::= a | the mean?
Difficulty: Easy
Section Reference 1: 24.3 Creating XML Documents
a) “digit must be equal to 012”
b) “digit can be replaced with 1 or 2”
c) “digit must start with 0 then 1 then 2"
d) “digit can be replaced with 0 or 1 or 2"
Title: In a grammar, what does <digit> ::= 0 | 1 | 2 mean?
Difficulty: Easy
Section Reference 1: 24.3 Creating XML Documents
71) Using the grammar notation in your textbook, which rule means that a verb can be either jumps over or eats?
a) <verb> ::= "jumps over" | "eats" | </verb>
b) <verb> ::= jumps over | eats
c) <verb> ::= jumps | over | eats
d) <verb> ::= <jumps over> | <eats> | </verb>
Title: What is the grammar rule for a verb that can be either jumps over or eats?
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
72) What package will you use to import DocumentBuilder?
a) javax.swing.DocumentBuilder
b) javax.xml.DocumentBuilder
c) javax.parsers.DocumentBuilder
d) javax.xml.parsers.DocumentBuilder
Title: What package will you use to import DocumentBuilder?
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
73) What package will you use to import Document?
a) javax.swing.Document
b) org.w3c.xml.Document
c) javax.parsers.Document
d) org.w3c.dom.Document
Title: What package will you use to import Document?
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents
74) What package will you use to import Element?
a) javax.swing.Element
b) org.w3c.xml.Element
c) javax.parsers.Element
d) org.w3c.dom.Element
Title: What package will you use to import Element?
Difficulty: Medium
Section Reference 1: 24.3 Creating XML Documents