Motivation

Figure 615. XML and application code Slide presentation Create comment in forum
<root>
  <bill amount="33.47"/> 

  <bill Amount="33.47"/>

  <Bill amount="20 bucks" />
</root>
Element bill = root.getChild("bill");
String a = bill.getAttributeValue("amount");
double amount = Double.parseDouble(a);

Correct record:

  • <bill> and amount are written correctly.

  • 33.74 is a float compatible string.

Error: Amount should be written using small caps.

Error:

  • <Bill> must be written using small caps.

  • 20 bucks is no float compatible string: parseDouble(a) yields an Exception.


Figure 616. HTML validity Slide presentation Create comment in forum
<html>
  <body> 
     <img source ="picture.png"/>
  </body>
  <heat> 
    <caption>Crappy HTML code</caption> 
  </heat>
</html>

Error:

  • <heat> needs replacement by <head>.

  • <head> and <body> appear in reverse order.

Errors:

  • An <img> requires an src rather than a source attribute.

  • The alt attribute is missing.

Error: <caption> must be replaced by <title>.


Figure 617. Well-formed and valid Slide presentation Create comment in forum
Well-formed Valid (Grammar)
  • Arbitrary element / attribute names.

  • Arbitrary element nesting.

  • No data types e.g. <bill amount="sorry!"/>, <money>2026/08/11</money>.

  • Restrict allowed element / attribute names.

  • Restrict parent / child relations.

  • Element / attribute value types based on an extensible type scheme.


Figure 618. XML grammar examples Slide presentation Create comment in forum