XML files: structure

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

XML files: structure

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which XML element is correctly written?
A <name>Mia</nme>
B <name>Mia</name>
2. Which statement about the root element of an XML file is correct?
A There is one root element that contains all the other elements
B Each element in the file must be its own separate root element
3. Which XML shows a child element correctly nested inside its parent?
A <student><name>Mia</name></student>
B <student><name>Mia</student></name>
4. How does XML describe the data it stores?
A Named tags such as <mark>88</mark> label each value
B Values are only separated by commas with no labels
5. Which line stores a value as an attribute of the element?
A <student id=7>Mia</student>
B <student id="7">Mia</student>

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1<student><name>Mia</name></student> AThe student element is never closed, so the XML is not well-formed. It needs a closing </student> tag.
2<student id="7"> BThe tags overlap. The name element must be closed before its parent student is closed, so the tags are not properly nested.
3Every element needs an opening tag and a matching closing tag with a forward slash C<name>Mia</name>
4A well-formed XML file has one root element that contains all the other elements D<students><student><name>Mia</name></student></students>
5<student><name>Mia</student></name> EAn opening tag with an attribute named id that has the value 7
6<student><name>Mia</name> FA student element with a child element name nested inside it, holding the data Mia

Definitions

<student><name>Mia</name></student>

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
<name>Mia<_name>
2.
<students> <student>Mia</student> </________>
3.
<student><____>Mia</name></student>
4.
<student id_"1"><name>Mia</name></student>
5.
<_______ id="1"><name>Mia</name></student>

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A <students>
B <student>Mia</studen>
C </students>
Question 2
A <school>
B <student>
C <name>Mia<name>
D </student>
E </school>
Question 3
A <student>
B <student id="1">Mia</student>
C </students>
Question 4
A <students>
B <student>
C <name id=7>Mia</name>
D </student>
E </students>
Question 5
A <school>
B <student>
C <name>Mia</name>
D <student>
E </school>

Answer Key

XML files: structure
Section A: Quick Questions
Q1
B — <name>Mia</name>
Q2
A — There is one root element that contains all the other elements
Q3
A — <student><name>Mia</name></student>
Q4
A — Named tags such as <mark>88</mark> label each value
Q5
B — <student id="7">Mia</student>
Section B: Match the Pairs
Q1
<student><name>Mia</name></student> → A student element with a child element name nested inside it, holding the data Mia
Q2
<student id="7"> → An opening tag with an attribute named id that has the value 7
Q3
Every element needs an opening tag and a matching closing tag with a forward slash → <name>Mia</name>
Q4
A well-formed XML file has one root element that contains all the other elements → <students><student><name>Mia</name></student></students>
Q5
<student><name>Mia</student></name> → The tags overlap. The name element must be closed before its parent student is closed, so the tags are not properly nested.
Q6
<student><name>Mia</name> → The student element is never closed, so the XML is not well-formed. It needs a closing </student> tag.
Section C: Definitions
Q1
<student><name>Mia</name></student> — XML stores data in nested, named elements. Each element has an opening and closing tag, and child elements sit inside a root element. The tags describe the data.
Section D: Fill in the Blanks
Q1
<name>Mia</name>
Q2
<students> <student>Mia</student> </students>
Q3
<student><name>Mia</name></student>
Q4
<student id="1"><name>Mia</name></student>
Q5
<student id="1"><name>Mia</name></student>
Section E: Spot the Error
Q1
B — The closing tag must match the opening tag exactly. It should be </student>, not </studen>.
Q2
C — The closing tag is missing its slash, so the name element is never closed. It should be </name>.
Q3
A — The root element's opening tag must match its closing tag </students>. It should be <students>.
Q4
C — Attribute values must be in quotes in well-formed XML. It should be id="7".
Q5
D — This line should close the student element with </student>. Without the slash it opens a new element instead.