Cover by Joe Fawcett, Liam R.E. Quin, Danny Ayers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

A

Answers to Exercises

CHAPTER 1 ANSWERS TO EXERCISES

Exercise 1 Solution

A sample document, now element-centric, is shown here:

<applicationUsers>
  <user>
    <firstName>Joe</firstName>
    <middleName>John</middleName>
    <lastName>Fawcett</lastName>
  </user>
  <user>
    <firstName>Danny</firstName>
    <middleName>John</middleName>
    <lastName>Ayers</lastName>
  </user>
  <user>
    <firstName>Catherine</firstName>
    <middleName>Elizabeth</middleName>
    <lastName>Middleton</lastName>
  </user>
</applicationUsers>

Exercise 2 Solution

The main disadvantage is that the size of the file is greatly increased. In general, each additional user needs an extra 72 bytes, compared to the original version. For a small number of users this probably won’t matter, but with a large number, or if you are transmitting many of these files, this could mean much more network traffic, leading to higher costs and reduced efficiency. This is one reason that, when designing an XML format for your data, it is recommended to choose attributes unless you have good reason not to.

CHAPTER 2 ANSWERS TO EXERCISES

Exercise 1 Solution

There are four errors altogether:

  • <xmlLibrary> is wrong as element names cannot begin with the letters XML whether uppercase or lowercase.
  • publicationYear=1898 is incorrect as all attribute values must be quoted, whether or not they contain spaces.
  • <title> Arms & The Man</title> is using a forbidden character, &, which needs be replaced with a entity reference, &amp;.
  • <play description> is illegal as it contains a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required