0% found this document useful (0 votes)
362 views10 pages

Introduction To XML: A. Multiple Choice Questions

XML is a markup language that allows encoding of documents using predefined tags. It is extensible, allowing custom tags to be defined. XML documents must have a root element enclosing all other elements. Elements can have attributes to provide additional information. Attributes must be enclosed in quotes. Comments are used for documentation and are denoted by <!-- comment --> in XML.

Uploaded by

Beena Mathew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
362 views10 pages

Introduction To XML: A. Multiple Choice Questions

XML is a markup language that allows encoding of documents using predefined tags. It is extensible, allowing custom tags to be defined. XML documents must have a root element enclosing all other elements. Elements can have attributes to provide additional information. Attributes must be enclosed in quotes. Comments are used for documentation and are denoted by <!-- comment --> in XML.

Uploaded by

Beena Mathew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Chapter

Chapter13
3

Introduction to XML

A. Multiple choice questions:


1. Attributes in XML should be enclosed within ________________.
a. single quotes

b. double quotes

c. both a and b

d. none of these

Ans. c. both a and b


2. Which among the following is not applicable in XML?
a. Attributes cannot contain multiple values.

b. Tags are not case sensitive.

c. Attributes cannot contain tree structures.

d. There should always be a root element.

Ans. b. Tags are not case sensitive.


3. The first line in a XML document is called a ________________.
a. preface

b. prologue

c. starter

d. prefix

Ans. b. prologue
4. The entity reference to define an apostrophe is ________________.
a. &phe

b. & trophe

c. &apos

d. & apostrophe

Ans. c. &apos
5. Which among the following is used to insert a comment in XML?
a. <!-- -->

b. //

c. /* */

d. <comment> </comment>

Ans. a. <!-- -->


6. Which among the following is not true for a Well Formed XML document?
a. XML documents must have a root element.

b. XML elements must have a closing tag

c. XML tags are case sensitive

d. XML documents should always have comments

Ans. d. XML documents should always have comments


7. Is this a well formed XML document?

<?xml version = 1.0?>

<note>

<to age = 29> Tove </to>

<from> John </from>

a. Yes

b. No

c. Cant say

d. None of these

Ans. b. No
8. Validating an XML document refers to an XML document that is ________________.
a. well formed

b. confirm to DTD

c. both a and b

Ans. c. both a and b

58

d. none of these

9. The use of DTD in XML development is:


a. required when validating XML documents
b. no longer necessary after the XML editor has been customized
c. used to direct conversion using the XSLT processor
d. a good guide to populating a template to be filled in when generating an XML document automatically.
Ans. a. required when validating XML documents
10. Valid XML document means
a. the document has root element
b. the document contains at least one or more root element
c. the XML document has DTD associated with it and it complies with that DTD
d. each element must nest inside any enclosing element properly
Ans. c. the XML document has DTD associated with it and it complies with that DTD
11. Which of the following XML fragments are well formed?
a. <element attribute=value>

b. <element attribute=value>

c. <element attribute=!value>

d. <element attribute=value>

Ans. b. <element attribute=value>


12. XML document can be viewed in
a. word processor

b. web browser

c. notepad

d. all of these

c. <name />

d. all of these

Ans. d. all of these


13. How is an empty element defined in XML?
a. <name></name>

b. <name/>

Ans. d. all of these


B. Fill in the blanks:
1. Every closing tag of an XML document is prefixed with / (slash).
2. The root element encloses all other elements in XML.
3. Empty elements are starting and closing tags without any content.
4. XML attributes are used to provide additional information about elements.
5. XML attributes should always be enclosed within quotes.
6. An XML parser is the component that deciphers the XML code.
7. Validator is a software that is used to check the syntax of a XML document.
8. Comments are remarks that are not part of the code but a part of documentation.
9. The entity reference for the greater than > symbol is &gt.
10. A tag within a tag is called a nested tag.
C. State whether the following statements are true or false:
1. XML like HTML is not case sensitive.

[False]

2. XML can be utilized to store information.

[True]

3. It is possible to create your own tags in XML.

[True]
59

4. You may have empty tags in XML.

[True]

5. Every XML document may not have a root element.

[False]

6. <message /> is a valid example of an empty tag.

[True]

7. You may not enclose values for attributes of tags in quotes.

[False]

8. You may have multiple values for an attribute.

[False]

9. The first line is the XML declaration is called the prolog.

[True]

10. It is not possible to provide comments in XML documents.


D. Answer the following questions:

[False]

1. What is XML?
Ans. XML stands for eXtensible Markup Language (XML) which is a markup language that
allows encoding of documents using a predefined set of rules which is both human-readable
and machine-readable.
2. State three characteristics of XML.
Ans. The three characteristics of HTML are:

i. XML is extensible. It permits the client to make his own tags and record structure.

ii. XML can be utilized to store information. Applications could be composed to store and
recover data.

iii. XML may be utilized to trade information.

3. State the differences between HTML and XML.


Ans. Difference between HTML and XML:
HTML
HTML is used to display data and to
focus on formatting of data.
HTML tags are predefined.

XML
XML is used to describe data and focus on what
data is.
XML tags are not predefined. It is possible to create
and define new tags as per your needs.
XML tags must have a closing tag. (only container
tags are allowed)

HTML tags may or may not have


closing tags. (Container tags and
Empty tags)
HTML tags are not case sensitive.

XML tags are case sensitive.

4. What do you understand by the term XML element?


Ans. XML elements are tags that forms a XML document. There are no predefined tags in XML
unlike HTML. You need to define your own tags in XML.
5. XML tags are case sensitive explain the comment with the help of an example.
Ans. XML tags are case sensitive unlike HTML tags which are not case sensitive. For example in
HTML the tag <FONT> and <font> is one and the same. But in XML such tags are treated
separately. Thus the tag <Message> is different from the tag <MESSAGE>. Also note that
the opening and closing tags must be written with the same case. For example:

<Message>This is incorrect</message>

<MESSAGE>This is correct</ MESSAGE >


60

6. Explain with a help of an example how root elements are placed in a XML document.
Ans. XML documents must contain one element that is the parent of all other elements. This
element is called the root element. The root element encloses all other elements in XML.
All other elements inside the root elements form the child element. The child element may
again contain subchild elements and subsequently more nested elements may be inserted.
The level of nesting may be extended up to any level. The structure of the XML file should
look like this:

<root>

<child>

<subchild>.....</subchild>

</child>

</root>

For example in case you need to store information of students (i.e., first name and last name)
of a certain school using an XML document it should look like this:

<school>

<student>

<serial> 1 </serial>

<firstname> Shaahn </firstname>

<lastname> Kohli </lastname>

</student>

<student>

<serial> 2 </serial>

<firstname> Subham </firstname>

<lastname> Karki </lastname>

</student>

<student>

<serial> 3</serial>

<firstname> Rohit </firstname>

<lastname> Agarwal </lastname>

</student>

</school>

You can see in the above example that the root element declared out here is <school> then
comes the child element <student> which in turn stores the <firstname> and <lastname> of
the student in the tags.

7. What are empty XML elements? Give an example.


Ans. An empty XML element document that is used to create a tag without any content.

For example if the <message> tag is to be specified without any content. It is valid to write
the tags as:

<message></message>
61

It can be written like this as well:

<message />

This sort of element syntax is called self-closing.

8. State the naming rules of XML elements.


Ans. XML elements must follow these naming rules:

Names can contain letters, numbers but no special characters. Thus <state1>, <sta1te>,
and <topper5> are valid but <state@>, <sta%te>, <tx,r> and <topper#> are invalid.

Names cannot start with a number. Thus <1state> is invalid.

Names cannot contain spaces. Thus <first name> and <last name> are invalid tags.

Any name can be used, no words are reserved.

9. What are attributes in XML?


Ans. XML attributes are used to describe XML elements, or to provide additional information
about elements. As you have already seen that in HTML, attributes provide additional
information about elements. For example:

<BODY BGCOLOR=GREEN>

You can see that the BGCOLOR attribute changes the background colour of the web page to
GREEN.

You can even create your own attributes in XML. The attribute values in XML must always be
quoted, which may be either single or double quotes. For example in XML a persons sex, can
be written as:

<person sex=female>

or written as:

<person sex=female>

10. What is a XML prolog?


Ans. A XML Prolog is the section at the beginning of an XML document which includes
everything that appears before the documents root element. The XML declaration, the
DOCTYPE and any processing instructions or comments may all be a part of it. Depending
on your needs, you can choose to include both, either, or neither of these items in your XML
document.
11. What are entity references?
Ans. An entity reference is an alternative name for a series of characters. You can use an entity in
the &name; format, where name is the name of the entity. There are some predefined entities
in XML, furthermore you can declare entities in a DTD (Document Type Definition). There
are 5 predefined entity references in XML:

&lt;
&gt;
&amp;
&apso;
&quot;

<
>
&

less then
greater then
ampersend
apsotrophe
quotation mark

62

12. What is comme0.6nts used for? How are comments provided in a XML document?
Ans. Comments are lines which are used for documentation and is completely ignored by the
browser for interpretation always begins with <!and ends with -->
13. What is DTD? What are the two ways to define DTD?
Ans. A Document Type Definition (DTD) is a file that defines the schema or structure of a
document encoded in XML. A DTD can be declared inline inside an XML document, or as
an external reference.
14. State the difference between SYSTEM and PUBLIC as used in DTD.
Ans. The SYSTEM keyword is used when the XML and DTD resides in the same machine. The
PUBLIC keyword is used when the DTD file is in the public domain.
15. State the significance of +, * and ? symbols used after child elements in DTD.
Ans. The + sign after a child element indicates that the child element occurs one or more times
inside the element.

The * sign after a child element indicates that the child element occurs zero or more times
inside the element.

The ? sign after a child element indicates that the child element occurs zero or one time
inside the element.

16. State the different attribute values that you can provide along with their usage.
Ans. The attribute list declaration ensures that the XML document contains valid attribute list for
an element. It has the general syntax:

<!ATTLIST element-name attribute-name attribute-type attribute-value>

element-name is the name of the element.

attribute-name is the name of the attribute.

attribute-type is the type of the attribute. Some common types used are :

attribute-value may be one of the following:

Common Attribute Type


CDATA
ID
NMTOKEN
ENTITY
Value
Value
#REQUIRED
#IMPLIED
#FIXED value

Meaning
The value is character data.
The value is a unique ID.
The value is a valid XML name.
The value.

Explanation
It is used to refer assing the default value of the attribute.
It is used to indicate that it is complulsory to give the attribute.
It is used to specify the fixed value for the attribute.
It is used to specify the fixed value for the attribute.

17. What does Well Formed XML document mean?


Ans. XML documents that abide by the syntax rules of XML documents are called Well Formed
XML document. The syntax rules for XML are:
63

XML documents must have a root element

XML elements must have a closing tag

XML tags are case sensitive

XML elements must be properly nested

XML attribute values must be quoted

18. How do you validate a XML document?


Ans. To validate an XML document a XML validator software is used. A XML validator is a
software that is used to check the syntax of your XML document.
19. What is an XML Parser?
Ans. An XML parser provides vital information to the program on how to read the file. It is built
in within the web browser.

An XML parser is the component that deciphers the XML code. Without a parser, your
code cannot be understood. Computers require instruction. An XML parser provides vital
information to the program on how to read the file. Parsers come in multiple formats and
styles. They can be freestanding software, libraries, modules and classes.

20. How do you view XML documents in a web browser?


Ans. It is possible for raw XML files to be viewed in all major browsers. But XML files are not
displayed as HTML pages but with colour-coded root and child elements. A plus (+) or
minus sign (-) to the left of the elements can be clicked to expand or collapse the element
structure. To view the raw XML source (without the + and - signs), select View Page
Source or View Source from the browser menu.

You may double click on the XML document through My Computer ( or Computer as in
Windows 7) to open it in the default browser.
E. Application-based questions:
1. XML document structure can be divided in which two parts? What is meant by valid XML
document (write three points)? Write the code to create an XML document to present the
following data:
Name
Srishti
Aditi

Job
Programmer
Designer

Department
Engineer
Marketing

Ans. The two parts of an XML document are XML Tree and DTD.

A Valid XML document abides by the following rules:

1. XML documents must have a root element

2. XML elements must have a closing tag

3. XML tags are case sensitive

<employees>

<emp>

<Job>Programmer</Job>

<Department>Engineer</Department>

<Name> Srishti</Name>

64

Cubicle
5E
19T

<Cubicle>5E</Cubicle>

</emp>

<emp>

<Name> Aditi</Name>

<Job> Designer </Job>

<Department> Marketing </Department>

<Cubicle>19T </Cubicle>

</emp>

</employee>

2. Draw the XML tree for the code given below:


<employees>

<employee sex= male>

<name>

<first> Harry </first>

<last> Potter </last>

</name>

</employee>

<employee sex= female>

<name>

<first>Linda</first>

<last> Ray </last>

</name>

</employee>

</employees>

Ans.

Root Element:
<employees>

Attribute:
sex

Element:
<employees>

Element:
<name>

Element:
<First>

Element:
<Last>

65

3. Draw the XML tree for the code given below:


<furniture>

<Table material= wood>

<Primary>100</Primary>

<Middle>150</Middle>

<Senior>150</Senior>

</Table>

<Table material= plastic>

<Primary>200</Primary>

<Middle>135</Middle>

<Senior>150</Senior>0

</Table>

</furniture>

Ans.
Root Element:
<furniture>

Attribute:
Material

Element:
<Table>

Element:
<Primary>

Element:
<Middle>

Element:
<Senior>

4. Create a DTD for storing book information for a library. The DTD should contain details
about each book in terms of title, author (name, nickname), no. of copies, all of which can
store character data. The no. of copies should contain two attributes named inhand and issued
which are both mandatory.
Ans.

<? xml version= 1.0 ?>

<!DOCTYPE LIBRARY[

<!ELEMENT LIBRARY (BOOK+)>

<!ELEMENT BOOK (TITLE, AUTHOR+, NOC)>

<!ELEMENT AUTHOR (NAME, NICKNAME)>

<!ELEMENT TITLE (#PCDATA)>

<!ELEMENT NAME (#PCDATA)>


66

<!ELEMENT NICNAME (#PCDATA)>

<!ELEMENT NOC (#PCDATA)>

<! ATTLIST NOC INHAND ISSUED CDATA #REQUIRED>

]>

5. Observe the DTD below and answer the following questions:


<? xml version= 1.0 ?>

<!DOCTYPE Company[

<!ELEMENT Company (Employee+)>

<!ELEMENT Employee (FirstName, LastName, ContactNo, Email)>

<!ELEMENT FirstName (#PCDATA)>

<!ELEMENT LastName (#PCDATA)>

<!ELEMENT ContactNo (#PCDATA)>

<!ELEMENT Email (#PCDATA)>

<! ATTLIST email address CDATA #REQUIRED>

]>

a. Name the root element of the above XML document.


Ans. Company
b. How many child elements are there in the above DTD? Name them.
Ans. Child Element: Employee, which again contains FirstName, LastName, ContactNo and
Email.
c. What does the + sign after the Employee element signify?
Ans. It signifies that the Employee occur one or more times inside the element.
d. Which of the element has an attribute associated with it? Name the element and also the
attribute associated with it.
Ans. Element: email and attribute: address
e. What is the basic difference between the keywords PCDATA and CDATA?
Ans. PCDATA stands for Parsed Character Data and XML parsers normally parse all the text in
an XML document.

CDATA - (Unparsed) Character Data is used about text data that should not be parsed by the
XML parser.

67

You might also like