XML exercise

    SEBA 
    CLASS- 10
    CHAPTER-5
    XML

    OBJECTIVES TYPES QUESTIONS

    1. Fill in the blanks:

    a. .xml is the extension of an XML file name.       

    b. XML attribute value should always be enclosed in double quotation marks double quote (“ ”) .

    c. An XML document can only have one root element.

    d. Some characters that have a special meaning in XML are called Reserved character.

    e. PCDATA stand for Parsed Character Data

    2.  Write T for True and F for False:

    a. An XML document can have only a limited number of child elements. FALSE

    b. XML is case sensitive. FALSE

    c. XML is designed to replace HTML. FALSE

    d. XML is a software and hardware dependent language used for carrying information. TRUE

    e. XML was developed as per W3Cs recommendation. TRUE

    3. Choose the correct answer:

    a. which one of the following is a valid name for an XML document and provide their relationship with each other.

    <student>

    b. Which of the following is the correct elements type declaration for the occurrence of the ‘First Name’ element and the ‘LastName’ element in order, as the child element of the ‘Name’ Element?

    <!ELEMENT Name (FirstName)>

    <!ELEMENT Name  (LastName)>

    c. Which of the following is used to specify the attribute list of an element?

    !ATLIST

    d. The character associated with elements that control how many times an element may appear in the XML document are.

    All of these.

    e. The statements for associating external DTD declaration with ‘item.dtd’ is

    <!DOCTYPE item SYSTEM “item.dtd”>


    Click To Top

    DESCRIPTIVE TYPE QUESTIONS

    1. Short answer Questions:

    a. What is DTD? List the two types of DTD?

    DTD is Abbreviated as Document Type Definition and it is defined to build legal building block of an XML document. The Two Types of DTD are:

    i) Internal DTD

    ii) External DTD

    b. What is XML parser? Define the two types of XML parsers.

    XML parser is a piece of software, which checks for a well-defined format and performed calidation of document. It also allows us to read, create and modify an existing XML document.. The two types of XML parsers are:

    i) Non-validating XML parser: It is a type of XML parser which checks if an XML document is well formed, i.e., if the document is properly marked up according to syntax rules. All browser are non-validating XML parsers. Example are openXML, Lark, XP, etc.

    ii) Validating SML parser: It is a type of XML parser which checks if an XML document is well formed, ensures that all elements in the document are exactly specified as in the DTD to which the document is bound, i.e., it checks the validity of XML document. Example are XML4C, XML4J etc.

    c. What does an attributes declaration contains?

    The attribute list declaration contains the following information:

    i) The element to which an attribute is associated.

    ii) The name of the attribute.

    iii) The type of the attribute.

    iv) The default value of the attribute.

    d. What are the four default values of an attribute?

    The four default values of an attribute are:

    i) #REQUIRED

    ii) #IMPLIED

    iii) #FIXED

    iv) #SUPPLIED

    e. What is an entity? What are its two types?

    An entity is a sequence of characters used to represent another sequence of characters.

    Its two types are:

    i) pre-define entity

    ii) user-defined entity


    2. Long Answer Questions:

    a. List five differences between HTML and XML

    The Five difference between HTML and XML are Given below:

    XML

    HTML

    1. XML was designed to store, carry and exchange data.

    2. In XML tags are user-define

    3. XML tag names are case sensitive

    4. In XML all ta must be enclosed

    5. In XML the attribute value should be surrounded double quote only

    1. HTML was designed to display it

    2. In HTML, Tag are pre-defined

    3. HTML tags names are not case sensitive

    4. In HTML it is not necessary to close each tag.

    5. In HTML the attribute value can be written without quotes, with double quotes, or single quotes.

    b. What are the rules for defining a well-formed XML document?

    The rules for defining a well-formed XML document are:

    i) The ‘root’ and ‘child’ element must be nested in a proper way.

    ii) Each start tag must have the corresponding end tag.

    iii) All empty tags must be enclosed properly.

    iv) As XML tags are case-sensitive, the start and the end tags must be of the same spelling and case.

    v) XML attribute values are enclosed within double quotation marks.

    c. Explain the different between comma and pipe symbol in deciding how element are used within the XML.

    The different between comma and pipe symbol in deciding how elements are used within an xml document are:

    i) In comma (,), the elements must appear strictly in the order in which they are defined in the element declaration whereas

    ii) In pipe (|), the elements may appear one or more times in any order.

    d. What is the difference in using the character? (? question mark), (* asterisk), and (+ plus) to control how many times an element appears in XML document?

    The difference in using the character? (? question mark), (* asterisk), and (+ plus) to control how many times an element appears in XML document are:

    i) (? Question mark) : This symbol indicates that an element may not appears at all or may appear once in XML document.

    ii) (*Asterisk): This symbol indicates that an element may not appear at all or may appear any number of times in the XML document.

    iii) (+Plus): This symbol indicates that an element may not appear at all or may appear any number of times in the XML document.

    e. Explain the four variations in specifying the value of an attribute by using an example each?

    The four variations in specifying the value of an attribute are:

    i) REQURIED: The value of the attribute must be supplied.

    ii) IMPLIED: The XML application decides which value of the attribute to use if no value is supplied.

    iii) FIXED: The value of the attribute is including in the declaration itself. The XML document must either supply the same value or nothing.

    iv) SUPPLIED: The DTD supplies the default value of the attribute if it is not provided in the XML document. If the value is supplied, The Supplied value is used.

    Examples:

    Attribute Type declaration in DTD code

    XML code

    <!ATLIST emp status CDATA #REQUIRED>

    <emp status = “Perameter”>

    <!ATLIST emp status CDATA #IMPLIED>

    <emp/> or <emp status = “Perameter”>

    <!ATLIST emp status CDATA #FIXED>

    <emp status/> or <emp status = “Perameter”>

    <!ATLIST emp status CDATA  >

    <emp status= “Temporary”/> or <emp status = “Contract”> or <emp status/>


    Click To Top

    APPLICATION BASED QUESTIONS

                

    1. Draw the XML tree for the cod give below:

    <movie>

    <thriller>

    <director> Amit Laxmi </director>

    </thriller>

    <fiction>

    <director> Raj Hirani </director>

    <releasedate> 15/12/2011 </releasedate>

    </fiction>

    </movie>

    XML tree Diagram



    2. Write the equivalent code for the following DD definition.

    <!ELEMENT myelement EMPTY>

    <myElement/> For execution of the code all empty tags and elements must be enclosed properly with / (slash) sign.

     

    3. Write any two possibilities of the XML document validation against the DTD given below:

    <!ELEMENT customer (#PCDATA)>

    <!ELEMENT name (#PCDATA)>

    <!ELEMENT email (#PCDATA)>

    <!ELEMENT phone (#PCDATA)>

    NOTE: According to DTD, there are some symbols that decide how many times an element can appear in XML document.

    Like if ?, then it may appear 0 or 1 time,

    And if *, then it may appear ) or many times,

    At last if +, then it may appear 1 or many times.

    1st Possible XML code:

    <customer>

         <name> Tom </name>

         <phone> 9984526325 </phone>

    </customer>

     

    2nd Possible XML code:

    <customer>

         <name> Tom </name>

         <email.> tom2@gmail.com </email>

         <phone> 9984526325 </phone>

    </customer>

    Since email was given with question mark (?), So it can appear 0 or 1 time in an XML document and I have wrote email 1 time in this (2nd code) and since phone was given (*) Asterisk, so it can be written 0 or many time and that why I Wrote it in both (1st and 2nd) code.

     

     

    4. Consider the XML document and answer the following questions:

    <?xml version 1.0>

    <customer name = Amy>

         <address>

               <add1> 13 Mahavir Enclave, South Ext. </add1>

               <city> Delhi </city>

               <country> India </country>

         </address>

    </customer>

    a. What is the use of the first line of code?

    The use of the first line of the code is to specify instructions to the browser on how to deal with XML document. (it is also known as Processing instruction line)

     

    b. Name the element that has an attribute in the above code?

    The element that has an attribute in the above code is <customer>

     

    c. Name the root element in the code.

    The root element in the code is <customer>

     

    d. List the child elements of <address>.

    The child elements of <address> are: add1, city, country.

     

     

    5. Consider the XML code given below and answer the questions.

    <book category = text>

         <bname> understanding XML </banana>

         <price> Rs. 75  </price>

    </book>

    a. How many elements are present in the above code?

    There are three elements present in the above code. They are:

    1. <book>

    2. <bname>

    3. <price>

     

    b. How many attributes are there in the above code? Name them.

    There is only one attributes in the above code. Its name is category.

     

     

     

     

     


    Click To Content