Creating a Valid Document

The document in Listing 2.2 can be successfully parsed by any XML parser because it doesn't violate any of XML's well-formedness constraints. But just because a document is well-formed doesn't mean that the contents are useful for a particular application. For instance, what if the restaurant owner made a mistake when he was updating the menu and accidentally gave an item two prices:

<item id="L3">
  <name>Pepsi</name>
  <price>$1.00</price>
  <price>$.75</price>
</item>

The document would still be parsed without generating errors, because it is still well-formed XML. But in the context of the actual application, having an item with two prices is definitely an error. At best, this would generate incorrect output (a menu ...

Get Strategic XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.