Introduction To XML: A. Multiple Choice Questions
Introduction To XML: A. Multiple Choice Questions
Chapter13
3
Introduction to XML
b. double quotes
c. both a and b
d. none of these
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>
<note>
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
58
d. none of these
b. <element attribute=value>
c. <element attribute=!value>
d. <element attribute=value>
b. web browser
c. notepad
d. all of these
c. <name />
d. all of these
b. <name/>
[False]
[True]
[True]
59
[True]
[False]
[True]
[False]
[False]
[True]
[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.
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)
<Message>This is incorrect</message>
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>
</student>
<student>
<serial> 2 </serial>
</student>
<student>
<serial> 3</serial>
</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.
For example if the <message> tag is to be specified without any content. It is valid to write
the tags as:
<message></message>
61
<message />
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 contain spaces. Thus <first name> and <last name> are invalid tags.
<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>
<
>
&
&apso;
"
<
>
&
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:
attribute-type is the type of the attribute. Some common types used are :
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.
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.
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.
<employees>
<emp>
<Job>Programmer</Job>
<Department>Engineer</Department>
<Name> Srishti</Name>
64
Cubicle
5E
19T
<Cubicle>5E</Cubicle>
</emp>
<emp>
<Name> Aditi</Name>
<Cubicle>19T </Cubicle>
</emp>
</employee>
<employees>
<name>
</name>
</employee>
<name>
<first>Linda</first>
</name>
</employee>
</employees>
Ans.
Root Element:
<employees>
Attribute:
sex
Element:
<employees>
Element:
<name>
Element:
<First>
Element:
<Last>
65
<furniture>
<Primary>100</Primary>
<Middle>150</Middle>
<Senior>150</Senior>
</Table>
<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.
<!DOCTYPE LIBRARY[
]>
<!DOCTYPE Company[
]>
CDATA - (Unparsed) Character Data is used about text data that should not be parsed by the
XML parser.
67