XML: Essential Concepts and Usage - Quiz
Total: 123 questions
1. What is XML?
2. Types of xml usages.
3. What document-oriented markup languages are used for?
4. What data-oriented markup languages are used for?
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?
6. What does an XML declaration declare?
7. Which encoding should have XML documents used in Web services?
8. Example of comment in XML.
Example of comment in XML.
<!-- This is a comment -->
9. What a CDATA section is used for?
10. Form of CDATA section.
Form of CDATA section.
<![CDATA[ text goes here ]]>
11. What is an XML namespace?
12. How to declare XML namespace?
13. Should the URI used for the XML namespace be unique to that markup language?
14. Should the URI used for the XML namespace always point to an actual resource or document?
15. How to define the default namespace for the element and all its descendants?
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?
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>
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?
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>
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?
21. What does a QName consist of?
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>
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.
24. Disadvantage of DTD.
25. Advantage of XML schema over DTD.
26. What do complex types describe?
27. What are simple types?
28. The name of the root element of a schema document?
29. Default namespace of all the XML schema elements.
Default namespace of all the XML schema elements.
"http://www.w3.org/2001/XMLSchema"
30. What does 'targetNamespace' attribute, defined in schema element, declare?
31. Base type in xml schema.
32. Are the names of XML schema types case-sensitive?
33. How multiplicity of an element is managed in xml schema?
34. Default value of maxOccurs and minOccurs.
35. How to indicate that an element is optional?
36. Can minOccurs and maxOccurs be negative?
37. Can maxOccurs value be less than minOccurs?
38. How to indicate that the element can occur an unlimited number of times?
39. How to declare occurrence constraints for attributes?
40. Values of 'use' occurrence constraint.
41. The default value of 'use' occurrence constraints.
42. Is it possible to set a default value for an attribute?
43. When a fixed value can be useful?
44. The difference between 'all' and 'sequence' elements.
45. How many times each element in an 'all' group can occur?
46. Can 'all' group contain other groupings? For example sequence or all?
47. The difference between 'local elements' and 'global elements' in the schema.
48. Can a schema define more than one global element?
49. Should the root element of a valid XML document have a corresponding global element declaration in the schema?
50. Can XML schema have global attributes?
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>
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.
53. Can global elements and attributes be unqualified?
54. The difference between qualified and unqualified elements.
55. Does default namespace apply to global attributes?
56. If a global element is a member of the default namespace, should it be qualified with a prefix?
57. Should local elements be qualified?
58. How to identify whether local elements should be qualified with a prefix or not?
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>
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>
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>
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.
63. How to identify the schemas' locations in the document?
64. Example of schemaLocation.
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?
66. What shemas are specified for in XML documents?
67. What the xsi:schemaLocation attribute is used for?
68. Can xsi:schemaLocation point at several schemas?
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">
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?
71. Should the schemas, identified by xsi:schemaLocation, belong to one of the namespaces identified in the XML instance document?
72. Where a schema can be located?
73. Should the xsi:schemaLocation attribute be defined in the root element of an XML document?
74. Should XML parsers use the schema identified by xsi:schemaLocation?
75. Does XML schema support type inheritance?
76. Types of inheritance that complex types can use.
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>
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.
79. Can one base type be used to create several derived types?
80. Can an element be omitted from a restriction if the parent type declared it to be not optional?
81. Can the derived type's occurrence constraints be less strict than those of its base type?
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"?
83. Requirements for the restricted occurrence attributes.
84. Can derived types be used polymorphically with elements of the base type?
85. How explicitly declare the type of the element in the instance document? When it is done?
86. Example of explicitly declaring an element's type with xsi:type.
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?
88. How to declare abstract type?
How to declare abstract type?
<complexType name="Exam" abstract="true">
89. The possible values for the final attribute.
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?
91. What existing simple types are derived for?
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.
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?
94. How many facet elements can the restriction element for simple types have?
95. What maxExclusive facet is used for?
96. What maxInclusive facet is used for?
97. What minInclusive facet is used for?
98. What minExclusive facet is used for?
99. What enumeration facet is used for?
100. What pattern facet is used for?
101. Example of using an Enumeration facet.
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?
103. Which type a list type can be based on?
104. What is NMTOKEN?
105. What is NMTOKENS?
106. Can NMTOKENS be used with elements?
107. Restriction for simple types on which list types can be based.
108. What is a union?
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>
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?
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>
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?
113. Can anonymous type contain named types?
114. Can anonymous types be based on complex types?
115. Can anonymous types be based on simple types?
116. What 'import' is used for?
117. What 'include' is used for?
What 'include' is used for?
'Include' allows combining schemas from the same namespace.
118. Example of importing a schema.
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.
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).