Tutorial "XML and related technologies" (60 questions)

Author: Razvan MIHAIU
razvan_rem@rem_mihaiu.name (please remove '_rem' and 'rem_')
From: www.mihaiu.name
Date: 11/04/2005

Page 1: XML questions 1-20

Page 2: XML questions 21-40

Page 3: XML questions 41-60

  1. How you declare a document type and how you define a document type ?


    To declare a document type you use a DOCTYPE tag:

    <!DOCTYPE RootElement SYSTEM "SomeDocumentTypeDefinitionFile.dtd">

    To define a document type you use DTD or XML Schema or Relax NG or Schematron.

  2. Can an attribute be specified in an element's closing tag ? Yes/No


    Answer: No.

  3. How many root elements can be found in a proper XML document ?


    Just 1 root element. The root element must be the first defined element.

  4. When should you include the standalone attribute in your xml declaration ?


    The standalone attribute means that the DTD is embedded in the XML document inside the DOCTYPE attribute. Because the use of this technique is discouraged, the standalone attribute should never be used.

  5. You have the following line in a DTD:
    <!ELEMENT Root (Description | Machine | Name | Node)+>

    Is the Description element mandatory in a valid XML file ?


    No. The sub-elements of Root are declared using the or '|' operator. No sub-element from the list is mandatory but at least 1 sub-element must be present because the cardinal operator used for all sub-elements is '+'.

  6. Is the following DTD valid ?
    <!ELEMENT Description (#PCDATA)> <!ATTLIST Description Author CDATA #FIXED >


    No. When the #FIXED attribute is specified you must provide a default value for the respective field - in this case "Author":

    <!ELEMENT Description (#PCDATA)> <!ATTLIST Description Author CDATA #FIXED "Razvan, MIHAIU" >
  7. A default value for an attribute is defined as:
    <!ELEMENT Description (#PCDATA)>> <!ATTLIST Description Author CDATA "DefaultVal" >

    What is happening if the parsed XML has a "Description" element that does not have the "Author" attribute ? Is this valid XML ?


    Yes. The parser will take the default value from the DTD file and it will supply that attribute as if it was read from the XML file itself. No parsing error is triggered.

  8. Is the following text valid XML ?
    <employee id="4"> <phone>00234567</phone type="work"> <phone>00434656</phone type="home"> </employee>


    No. Attrbutes *cannot* be specified in the ending tags.

  9. Is the following text valid XML ?
    <employee id="4" phone="00234567" phone="00434656">Teo Leo</employee>


    No. There cannot be 2 attributes with the same name (phone in this case). The above text can become valid XML if it is written like this:

    <employee id="4"> <name>Teo Leo</name> <phone>00234567</phone> <phone>00434656</phone> </employee>
  10. Is the order of attributes preserved according to the XML specification ? Yes/No


    No. The specification does not mentions this, so the order of attributes is not guaranteed.

  11. Is the order of elements preserved according to the XML specification ?


    Yes. The order in which the elements are defined must be retained. The XML specification specifically mention this issue so any parser that do not follow this rule is invalid.

  12. Is the following text valid XML ?
    <employee id="4"> <name>Teo Leo</employee> </name>


    No. Tags can be nested but *not* interlaced.

  13. What are the three main activities enabled by the DOM model ?


    1. Navigating the hierarchy tree
    2. Viewing information (get)
    3. Modifying information(put, delete, add, move, etc.)
  14. Can you navigate the attribute sequencially using the DOM APIs? Yes/No


    Yes. It can be done, but the more useful approach is to use the attribute's name to get it because the application cannot handle unknown attributes anyway.

  15. Which class can be used to create an empty DOM document ?


    DocumentBuilderFactory & DocumentBuilder. Take a look at the following code:

    import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); doc = docBuilder.newDocument();
  16. What is the correct string to start an xml file ?
    • <?xml version="1.0" encoding="UTF-8"?>
    • <?xml version="1.0" encoding="UTF-8">


    First form.

  17. Is the following DTD declaration valid ?
    <!DOCTYPE personnel SYSTEM "./dtd/RplClient.dtd" -->


    No. A tag must end with ">" and not with "-->". Only comments can end with "-->".

  18. Is the following DTD definition valid ? Yes/No
    <!ELEMENT RPLClient TestSession>


    No. The "content category" of an element can only be "ANY" or "EMPTY", thus the following definitions are valid:


    A "content model" can only be specified between paranthesis:

    <!ELEMENT RPLClient (TestSession)>

    This element - "RPLClient" - has one mandatory children of type name "TestSession".

  19. Is DTD part of the XML 1.0 specification ? Yes/No


    Yes. Because of this the use of DTD is very widespread.

  20. Can you associate many DTDs with an XML document ? Yes/No


    No. Only one DTD can be associated with a given XML document but the DTD can be specified simultaneously in the XML document itself (in this case it's called an 'internal subset') and in an external file (in this case it's called an 'external subset').

I wish you success in your certification effort.

Best regards,

Razvan Mihaiu � 2000 - 2017