XML: Essential Concepts and Usage - Quiz

Total: 123 questions

1. What is XML?
The eXtensible Markup Language (XML) is a meta-language - language for defining other languages.
2. Types of xml usages.
XML is used for two different purposes: document-oriented and data-oriented applications.
3. What document-oriented markup languages are used for?
Document-oriented markup languages like XHTML and DocBook are focused on the format and presentation of literature. They describe how books, magazines, and business and scientific papers are organized, and how they look.
4. 

What data-oriented markup languages are used for?

They focus on how data is typed and organized; they declare a schema for storing and exchanging data between software applications.

5. Is XML declaration mandatory?
No, it is optional.
6. What does an XML declaration declare?
- the version of XML; - the character encoding; - whether the document is standalone or not.
7. Which encoding should have XML documents used in Web services?
UTF-8 or UTF-16.
8. 

Example of comment in XML.

<!-- This is a comment -->
9. What a CDATA section is used for?
It gives the possibility to mark a section of text as literal so that it will not be parsed for tags and symbols, but will instead be considered just a string of characters.
10. 

Form of CDATA section.

<![CDATA[ text goes here ]]>
11. What is an XML namespace?
It provides a qualified name for an XML element or attribute.
12. How to declare XML namespace?
The xmlns attribute is used, for example: xmlns="someURI". The value of an xmlns attribute is a URI reference.
13. Should the URI used for the XML namespace be unique to that markup language?
Yes.
14. Should the URI used for the XML namespace always point to an actual resource or document?
No.
15. How to define the default namespace for the element and all its descendants?
xmlns="someURI" for element.
16. 

There is an example:

<?xml version="1.0" encoding="UTF-8" ?>
<exam date="2015-05-21"
 xmlns = "http://www.ec.com/EX/">
   <examName>JPA</examName>
   <examNumber>78</examNumber>

   <group xmlns = "http://www.ec.com/GR">
      <name>Java</name>
      <id>2</id>
  </group>
</exam>

a) To which elements does xmlns, declared in the group element, apply?

b) To which elements does xmlns, declared in the exam element, apply?

a) To the group, name and id elements.

b) To all the elements except the group elements, because the group element overrides the default namespace of the exam element to define its own default namespace.

17. 

Rewrite the example declaring and using namespaces prefixes in XML:

<?xml version="1.0" encoding="UTF-8" ?>
<exam date="2015-08-21"
 xmlns = "http://www.ec.com/EX">
   <examName>JPA</examName>
   <examNumber>923</examNumber>

   <group xmlns="http://www.ec.com/GR">
      <name>JAVA</name>
      <id>18</id>
   </group>
</exam>
<?xml version="1.0" encoding="UTF-8" ?>
<ex:exam date="2015-08-21"
   xmlns:ex = "http://www.ec.com/EX"
   xmlns:gr ="http://www.ec.com/GR">

   <ex:examName>JPA</ex:examName>
   <ex:examNumber>923</ex:examNumber>

   <gr:group>
      <gr:name>JAVA</gr:name>
      <gr:id>18</gr:id>
   </gr:group>
</ex:exam>
18. 

Is it possible to combine default namespaces and namespaces prefixes in XML?

Yes.

19. 

Rewrite the example declaring default namespaces for 'exam' element and namespaces prefix for group.

<?xml version="1.0" encoding="UTF-8" ?>
<exam date="2015-08-21">
   <examName>JPA</examName>
   <examNumber>923</examNumber>

   <group>
      <name>JAVA</name>
      <id>18</id>
   </group>
</exam>
<?xml version="1.0" encoding="UTF-8" ?>
<exam date="2015-08-21"
 xmlns = "http://www.ec.com/EX"
 xmlns:gr="http://www.ec.com/GR">
   <examName>JPA</examName>
   <examNumber>923</examNumber>

   <gr:group>
      <gr:name>JAVA</gr:name>
      <gr:id>18</gr:id>
   </gr:group>
</exam>
20. What is a QName?
QName stands for "qualified name", it is a prefix combined with an element name.
21. What does a QName consist of?
Of the XML namespace and the local name.
22. 

What is Qname of name element in this example?

<?xml version="1.0" encoding="UTF-8" ?>
<exam date="2015-08-21"
 xmlns = "http://www.ec.com/EX"
 xmlns:gr = "http://www.ec.com/GR">
   <examName>JPA</examName>
   <examNumber>923</examNumber>

   <gr:group>
      <gr:name>JAVA</gr:name>
      <gr:id>18</gr:id>
   </gr:group>
</exam>

It is composed of the http://www.ec.com/GR XML namespace and the name local name.

23. Ways to describe XML markup languages.
- Document Type Definition (DTD) - XML schema
24. Disadvantage of DTD.
DTDs have a very weak typing system that restricts elements to four broad types of data: EMPTY, ANY, element content, or mixed element-and-text content.
25. Advantage of XML schema over DTD.
XML schema provides a much stronger type system and type inheritance. It supports the use of XML namespaces as well.
26. What do complex types describe?
How elements are organized and nested.
27. What are simple types?
The primitive data types contained by elements and attributes.
28. The name of the root element of a schema document?
The 'schema'.
29. 

Default namespace of all the XML schema elements.

"http://www.w3.org/2001/XMLSchema"
30. What does 'targetNamespace' attribute, defined in schema element, declare?
The XML namespace of new types created within the schema.
31. Base type in xml schema.
AnyType.
32. Are the names of XML schema types case-sensitive?
Yes.
33. How multiplicity of an element is managed in xml schema?
By occurrence constraints, which are declared by the maxOccurs and minOccurs attributes.
34. Default value of maxOccurs and minOccurs.
"1".
35. How to indicate that an element is optional?
The minOccurs attribute is set to "0".
36. Can minOccurs and maxOccurs be negative?
No. They should be 0 or positive.
37. Can maxOccurs value be less than minOccurs?
No. It should be equal or greater than minOccurs.
38. How to indicate that the element can occur an unlimited number of times?
Set a maxOccurs value to be "unbounded".
39. How to declare occurrence constraints for attributes?
Declare the 'use' occurrence constraint.
40. Values of 'use' occurrence constraint.
It can be "required", "optional", "prohibited".
41. The default value of 'use' occurrence constraints.
Optional.
42. Is it possible to set a default value for an attribute?
Yes.
43. When a fixed value can be useful?
For example, if a particular schema is assigned a version number, then that version number should be fixed for that schema.
44. The difference between 'all' and 'sequence' elements.
Sequence element defines the exact order of child elements and all element allows the elements to appear in any order.
45. How many times each element in an 'all' group can occur?
Once or not at all.
46. Can 'all' group contain other groupings? For example sequence or all?
No.
47. The difference between 'local elements' and 'global elements' in the schema.
Local elements are declared within the scope of a complex type and global elements as direct children of the schema element.
48. Can a schema define more than one global element?
Yes.
49. Should the root element of a valid XML document have a corresponding global element declaration in the schema?
Yes.
50. Can XML schema have global attributes?
Yes.
51. 

Name global and local elements

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schema
    xmlns = "http://www.w3.org /2001/ XMLSchema"
    xmlns:ec = "http://www.examclouds"
    targetNamespace = "http://www.examclouds">

  <element name="group" type = "ec:Group"/>
  <element name="exam" type = "ec:Exam"/>
  <complexType name = "Exam">
    <sequence>
      <element name = "examName" type = "string"/>
      <element name = "examNumber" type = "unsignedShort"/>
      <element name = "group" type = "ec:Group"/>
  </sequence>
    <attribute name = "date" type = "date"/>
  </complexType>
  <complexType name = "Group">
    <sequence>
      <element name = "name" type = "string"/>
      <element name = "id" type = "unsignedShort"/>
    </sequence>
  </complexType>
  ...
</schema>

Global elements are 'exam' and 'group'. Local elements are 'examName', 'examNumber', 'group', 'name', 'id'.

52. An example of a standard global attribute.
xml:lang.
53. Can global elements and attributes be unqualified?
No.
54. The difference between qualified and unqualified elements.
Qualified elements are with namespace and unqualified without.
55. Does default namespace apply to global attributes?
No. Global attributes must always be prefixed.
56. If a global element is a member of the default namespace, should it be qualified with a prefix?
No - all unqualified elements are assumed to be part of the default namespace.
57. Should local elements be qualified?
It isn't mandatory.
58. How to identify whether local elements should be qualified with a prefix or not?
There are two attributes for this purpose: 'elementFormDefault' and 'attributeFormDefault'.
59. 

Modify schema to require namespace prefixes on all local elements:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns = "http://www.w3.org/ 2001/ XMLSchema"
 xmlns:ec = "http://www.examclouds.com"
 targetNamespace = http://www.examclouds.com">

    <element name="group" type="ec:Group" />

    <complexType name="Group">
      <sequence>
        <element name="name"    type="string" />
        <element name="id"  type="string" />
      
      </sequence>
    </complexType>
    ...
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
 xmlns:ec="http://www.examclouds.com"
 targetNamespace="http://www.examclouds.com"
 elementFormDefault="qualified" >

   <element name="group" type="ec:Group" />

    <complexType name="Group">
      <sequence>
        <element name="name"    type="string" />
        <element name="id"  type="string" />
      
      </sequence>
    </complexType>
    ...
</schema>
60. 

Write an XML instance that conforms to the schema

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns = "http://www.w3.org/ 2001/ XMLSchema"
 xmlns:ec = "http://www.examclouds.com"
 targetNamespace = http://www.examclouds.com"
 elementFormDefault = "qualified" >

   <element name="group" type="ec:Group" />
   <complexType name="Group">
      <sequence>
        <element name="name"    type="string" />
        <element name="id"  type="string" />
      
      </sequence>
    </complexType>
    ...
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<ec:group
 xmlns:ec="http:///www.examclouds.com" >
  <ec:name>JPA</ec:name>
  <ec:id>34H</ec:id>
</ec:group>
61. 

Write an XML instance that conforms to the schema

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns = "http://www.w3.org/ 2001/ XMLSchema"
 xmlns:ec = "http://www.examclouds.com"
 targetNamespace = http://www.examclouds.com"
 elementFormDefault = "qualified" >

    <element name="group" type="ec:Group" />
    <complexType name="Group">
      <sequence>
         <element name="name"    type="string" />
         <element name="id"      type="string" />
      </sequence>
    </complexType>
    ...
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<ec:group
 xmlns:ec="http:///www.examclouds.com" >
  <name>JPA</name>
  <id>156G</street>
</ec:group>
62. The default value of the elementFormDefault and the attributeFormDefault.
It is "unqualified".
63. How to identify the schemas' locations in the document?
By using the schemaLocation attribute.
64. 

Example of schemaLocation.

<?xml version="1.0" encoding="UTF-8"?>
<exam date="2015-08-22"
   xmlns="http://www.examclouds.com/exams"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="www.examclouds.com/exams
       http://www.examclouds.com/exams/ec.xsd">
....
65. What is xmlns:xsi = "http://www.w3.org/ 2001/ XMLSchema-instance?
It is the XML schema-instance namespace, which is defined by the XML schema specification.
66. What shemas are specified for in XML documents?
To validate an XML document against schemas.
67. What the xsi:schemaLocation attribute is used for?
It helps an XML processor locate the actual physical schema document used by the XML instance.
68. Can xsi:schemaLocation point at several schemas?
Yes.
69. 

Is it correct declaration of schemaLocation?

<?xml version="1.0" encoding="UTF-8"?>
<exam date="2015-08-22"
  xmlns = "http://www.ec.com/exams"
  xmlns:xsi = "http://www.w3.org/ 2001/ XMLSchema-instance"
  xsi:schemaLocation = "http://www.ec.com/exams
                      http://www.ec.com/exams/ec.xsd

                      http://www.w3.org/ 2001/ XMLSchema-instance
                      http://www.w3.org/ 2001/ XMLSchema.xsd">

 

Yes.

70. Should XML schema-instance schema location be always specified?
No.
71. Should the schemas, identified by xsi:schemaLocation, belong to one of the namespaces identified in the XML instance document?
Yes.
72. Where a schema can be located?
On the Internet or on a local hard drive.
73. Should the xsi:schemaLocation attribute be defined in the root element of an XML document?
No, it can be defined later in the document, as long as it's in the scope of the elements it applies to.
74. Should XML parsers use the schema identified by xsi:schemaLocation?
XML parsers are not required to use the schema identified by xsi:schemaLocation, but a good parser will.
75. Does XML schema support type inheritance?
Yes.
76. Types of inheritance that complex types can use.
Extension and restriction.
77. 

Add a new type which is an extension of a base type Exam

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schema
  targetNamespace = "http://www.ec.com/exams"
  xmlns:ec = "http://www.ec.com/exams"
  xmlns = "http://www.w3.org/ 2001/ XMLSchema"
  elementFormDefault = "qualified">

<element name = "exam" type = "ec:Exam"/>

<complexType name="Exam">
    <sequence>
      <element name="name" type="string"/>
      <element name="number" type="string"/>
    </sequence>
    <attribute name="category" type="string"/>
  </complexType>

  ...
</schema>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schema
  targetNamespace = "http://www.ec.com/exams"
  xmlns:ec = "http://www.ec.com/exams"
  xmlns = "http://www.w3.org/ 2001/ XMLSchema"
  elementFormDefault = "qualified">

<element name="exam" type="ec:Exam"/>

<complexType name="Exam">
    <sequence>
      <element name="name" type="string"/>
      <element name="number" type="string"/>
    </sequence>
    <attribute name="category" type="string"/>
  </complexType>

  <complexType name="EnterExam">
    <complexContent>
      <extension base="ec:Exam">
        <sequence>
          <element name="location" type="string"/>
         
        </sequence>
      </extension>
    </complexContent>
  </complexType>
  ...
</schema>
78. The difference between extension and restriction inheritance.
Extension broadens a derived type by adding elements or attributes not present in the base type, while restriction narrows a derived type by omitting or constraining elements and attributes defined by the base type.
79. Can one base type be used to create several derived types?
Yes.
80. Can an element be omitted from a restriction if the parent type declared it to be not optional?
No.
81. Can the derived type's occurrence constraints be less strict than those of its base type?
No.
82. Can an element be constrained to minOccurs="0" and maxOccurs="4" in the child if the parent's element is defined as minOccurs="1" and maxOccurs="2"?
No.
83. Requirements for the restricted occurrence attributes.
The restricted occurrence attributes must fall within the boundaries defined by the parent type.
84. Can derived types be used polymorphically with elements of the base type?
Yes.
85. How explicitly declare the type of the element in the instance document? When it is done?
With the xsi:type attribute. It is used when an instance document use any type derived from declared.
86. 

Example of explicitly declaring an element's type with xsi:type.

<shipAddress xsi:type="mh:UKAddress">
87. Can complex types be declared to be abstract?
Yes.
88. 

How to declare abstract type?

<complexType name="Exam" abstract="true">
89. 

The possible values for the final attribute.

a) "restriction" - it can be extended but not restricted;

b) "extension" - prevents it from being extended but allows restriction;

c) "#all" - the type cannot be used as a base type at all.

90. Can new simple types that are derived from existing simple types be created?
Yes.
91. What existing simple types are derived for?
In order to constrain further the range of possible values that a simple type may represent.
92. 

Create a new type derived from simple, which restricts the built-in float type and limit the value of the element to be between 0 and 100000.

<simpleType name="Amount">
  <restriction base="float">
    <minInclusive value="0"/>
    <maxExclusive value="100000"/>
  </restriction>
</simpleType>
93. What is facet?
A facet is an element that represents an aspect or characteristic of the built-in type that can be modified.
94. How many facet elements can the restriction element for simple types have?
One or more facet elements.
95. What maxExclusive facet is used for?
The exclusive upper bound. The value must be less than this amount.
96. What maxInclusive facet is used for?
The inclusive upper bound. The value may not exceed this amount.
97. What minInclusive facet is used for?
The inclusive lower bound. The value must be at least this amount.
98. What minExclusive facet is used for?
The exclusive lower bound. The value must be greater than this amount.
99. What enumeration facet is used for?
To specify the set of allowed values.
100. What pattern facet is used for?
The format of the value, defined using a regular expression.
101. 

Example of using an Enumeration facet.

<simpleType name="Size">
   <restriction base="string">
      <enumeration value="S"/> 
      <enumeration value="M"/> 
      <enumeration value="L"/> 
   </restriction>
</simpleType>
102. Which facets a list type can have?
Length, minLength, maxLength and enumeration facets.
103. Which type a list type can be based on?
On any simple type, built-in or derived, but not on other list types or on complex types.
104. What is NMTOKEN?
NMTOKEN is a simple type, which is a string without spaces, line feeds, or tabs.
105. What is NMTOKENS?
A list of the NMTOKEN simple type.
106. Can NMTOKENS be used with elements?
No, only with attributes.
107. Restriction for simple types on which list types can be based.
List types should be based on simple types that do not have spaces because the parser assumes that spaces separate values in the list.
108. What is a union?
A set of valid simple types.
109. 

Can an element or attribute based on Size union type contain a mix of values?

<simpleType name="Size">
   <union memberTypes="ec:LiteralSize ec:NumberSize"/>
</simpleType>

No, it can hold either a LiteralSize or a NumberSize.

110. Can anonymous types be referred to outside the element that declares them?
No.
111. 

Combine an element declaration with a complex or simple type declaration and create an anonymous type.

<element name="exam" type="ec:Exam"/>

<complexType name="Exam">
  <sequence>
    <element name="name" type="string"/>
    <element name="number" type="unsignedShort"/>
  </sequence>
  <attribute name="examDate" type="date"/>
</complexType>
<element name="exam">
  <complexType>
    <sequence>
      <element name="name" type="string"/>
      <element name="number" type="unsignedShort"/>
     </sequence>
    <attribute name="examDate" type="date"/>
  </complexType>
</element>
112. Can anonymous type contain other anonymous types?
Yes.
113. Can anonymous type contain named types?
Yes.
114. Can anonymous types be based on complex types?
Yes.
115. Can anonymous types be based on simple types?
Yes.
116. What 'import' is used for?
An import gives a possibility to combine schemas from different namespaces.
117. 

What 'include' is used for?

'Include' allows combining schemas from the same namespace.

118. 

Example of importing a schema.

<?xml version="1.0" encoding="UTF-8" ?>
<schema
  targetNamespace="http://www.ec.com/exams/EC"
  xmlns:ec="http://www.ec.com/exams/EC"
  xmlns:gr="http://www.ec.com/exams/GR"
  xmlns="http://www.w3.org/2001/XMLSchema">

 <import namespace="http://www.ec.com/exams/GR"
  schemaLocation="http://www.ec.com/exams/group.xsd" />
  <element name="exam" type="ec:Exam"/>
119. 

Requirements for valid element and attribute name.

An element name must begin with a letter or underscore but must not start with the characters 'xml' and must not contain any of the following characters: /, <, >, ?, ", @, &, : (and some additional characters).

120. Can attributes be nested?
No.
121. Describe 'choice' element.
The 'choice' element lets one of the elements contained in the 'choice' element to be present in the containing element.
122. What 'simpleContent' element is used for?
It gives the possibility to add attributes to global simple types. It can be used to extend or restrict attributes on other complex types with simple content.
123. What 'anyAttribute' element is used for?
The attributes can be included in the header block XML schema without directly referencing the global attribute by using the 'anyAttribute' element.
Page 1 of 1