18. XML Quiz
Test yourself
Choose an answer for each question. You get feedback straight away, and your best score is saved on this device.
What does XML stand for?
- eXtra Markup Language
- eXtensible Markup Language
- Executable Markup Logic
- eXchange Machine Language
XML is eXtensible Markup Language. It is a format for describing and carrying data with tags you invent.
How many root elements must a well-formed XML document have?
- None
- As many as you like
- Exactly one
- At least two
Every XML document needs a single root element that contains everything else.
Which of these is NOT allowed in well-formed XML?
<a><b>text</a></b><item id="1"/><note date='2026-03-15'>Hi</note><empty></empty>
The first line crosses its tags: the inner element must be closed before the outer one.
How do you write an ampersand inside XML text?
&on its own\&∧&
A raw ampersand starts an entity reference, so it must be written as &.
Are the tags <Name> and <name> the same in XML?
- Yes, XML ignores capital letters
- No, XML is case sensitive
- Only inside attributes
- Only in the root element
XML names are case sensitive, so start and end tags must match exactly.
As a general guide, what should attributes be used for?
- The main data of the document
- Lists of several values
- Metadata about the data, such as an ID or a unit
- Comments
A common rule is elements for the data itself and attributes for information about it.
What problem do XML namespaces solve?
- Name clashes between different vocabularies
- Slow parsing
- Missing closing tags
- Large file sizes
A namespace says which vocabulary a name belongs to, so two elements called table can be told apart.
What is the difference between well-formed and valid?
- They mean the same thing
- Valid files need no closing tags
- Well-formed files must use a schema
- Well-formed follows the XML syntax rules, and valid also follows a DTD or schema
Every valid file is well-formed, but a well-formed file can still break the rules in its schema.
Which is an advantage of XML Schema (XSD) over a DTD?
- It is not written in XML
- It has real data types, such as numbers and dates
- Browsers validate it automatically
- It cannot restrict values
An XSD is written in XML, supports namespaces, and can say that a value must be a number, a date, or within a range. Browsers do not validate either format on their own.
In XPath, what does //book[price > 20]/title select?
- The price of every title
- Only the first book
- The title of every book that costs more than 20
- All books with no title
//book finds books anywhere, the predicate keeps those over 20, and /title picks each one’s title.
What is XSLT used for?
- Transforming XML into another document, such as HTML
- Storing images
- Encrypting XML files
- Running database queries
XSLT uses templates and XPath to turn XML into HTML, text, or other XML.
After DOMParser.parseFromString() reads bad XML, what happens?
- It always throws an exception
- It returns a document containing a
parsererrorelement, so you must check for it - It silently repairs the XML
- It returns
null
The parser does not throw. Look for a parsererror element to detect a failure.
Which is a good reason to choose XML over JSON?
- XML is always shorter
- XML has built-in number and boolean types
- You are marking up documents with mixed text and tags, or following an XML standard such as RSS or SVG
- XML needs no parser
XML suits documents, namespaces, strong schemas, and existing XML standards. JSON is usually shorter and easier in JavaScript.
What should you do when your program reads XML that came from an outside source?
- Treat it as untrusted: validate it, disable external entities, and escape it before showing it
- Trust it, because XML is strict
- Insert it into the page with
innerHTML - Enable every parser option for full features
Data from outside can be wrong or hostile. Turn off external entity loading, check the structure, and use textContent or escaping when you display it.
What next?
You have finished the XML course, and with it all five courses on BeingXpert. Use what you have learned to build real projects, and keep the Resources page handy for the official documentation.