Skip to main content

Exercises 15.1 eXtensible Markup Language - XML

XML is a mark-up language. HTML is also a mark-up language. XML looks very similar to HTML, but it is different from XML.
Some of the differences between XML and HTML are:
  • XML is used to store and transport data, not to create web pages like HTML.
  • XML tags are not predefined, but HTML tags are.
  • XML can be extended (you can add new tags). You can not add new tags to HTML.
For more information on XML see https://www.w3schools.com/xml/default.asp 1 .
Here is a sample of an XML document:
<person>
  <name>Chuck</name>
  <phone type="intl">
    +1 734 303 4456
  </phone>
  <email hide="yes" />
</person>
Each pair of opening (e.g., <person>) and closing tags (e.g., <\person>) represents a element or node with the same name as the tag (e.g., person). Each element can have some text, some attributes (e.g., hide), and other nested elements. If an XML element is empty (i.e., has no content), then it may be depicted by a self-closing tag (e.g., <email />).

1.

    csp-10-2-1: In XML, a pair of opening and closing tags (<> and <\>) represent what? Select all that apply.
  • element
  • A pair of tags in XML can represent an element.
  • string
  • A pair of tags in XML does not represent a string.
  • node
  • A pair of tags in XML can represent a node.
  • method
  • A pair of tags in XML does not represent methods.
Often it is helpful to think of an XML document as a tree structure where there is a top/root element (here: person), and other tags (e.g., phone) are drawn as children of their parent elements.
Figure 15.1.1.

2.

    csp-10-2-2: What are the sibling tags of the email tag?
  • person
  • The person tag is the parent tag of the email tag.
  • name
  • The name tag is a sibling of the email tag.
  • phone
  • The phone tag is a sibling of the email tag.
  • hide
  • The hide is an attribute name of the email tag.

3.

4.

5.

Properly Formatted XML

6.

Put the blocks into order to define just the body of simple XML document that defines a note. A note has a date, subject, and a body in that order. Indent the blocks to show the structure (parent and child).

7.

Put the blocks into order to define just the body of simple XML document that stores information for a message: to, from, time, subject, and body in that order. Indent the blocks to show the structure (parent and child).

8.

    csp-10-2-8: Select all of the following that are true about XML.
  • There must be a root tag
  • Correct! There must be a root tag.
  • The case of tags doesn't matter
  • Incorrect. Case matters.
  • All elements must be closed
  • Correct! All elements must be closed.
  • Attribute values must be in quotes
  • Correct! Attribute values must be in quotes.

9.

10.

    csp-10-2-10: Select the child tag of the bookstore tag.
  • title
  • The title tag is a grandchild of the bookstore tag. It is the child of the book tag.
  • author
  • The author tag is a grandchild of the bookstore tag. It is the child of the book tag.
  • year
  • The year tag is a grandchild of the bookstore tag. It is the child of the book tag.
  • book
  • Correct! The book tag is a child tag of the bookstore tag.

11.

    csp-10-2-11: Select all of the attribute values in the example XML for a bookstore.
  • category
  • No, category is the attribute name.
  • children
  • Correct, "children" is a value of the category attribute.
  • lang
  • No, lang is the attribute name.
  • en
  • Correct, "en" is a value for the lang attribute.

12.

    csp-10-2-12: Select all of the following that are true.
  • An element in XML that is empty (does not have content) can use self-closing tags.
  • Correct! An element in XML that is empty (does not have content) can use self-closing tags.
  • Nodes in XML can have parent and children nodes.
  • Correct! Nodes in XML can have parent and children nodes.
  • XML has predefined (standard) tags.
  • Incorrect. HTML has predefined (standard) tags but XML does not.
  • XML has opening and closing tags like HTML.
  • Correct! XML does have opening and closing tags like HTML.
  • XML is the standard language for describing web pages.
  • Incorrect. HTML is the standard language for describing web pages. XML is used to describe data.
https://www.w3schools.com/xml/default.asp