Complex type extension

The XOM takes complex type extensions into account.

Extending a complex type by adding an attribute

In this example, the complex type book has been extended to computer-book by adding a new attribute named language. The example includes a rule named processComputerBook that matches “Java” with the title of a ComputerBook object.

Here is the schema:

<complexType name= "book" >
 <sequence>
   <element name="ident" type="string"/>
   <element name="title" type="string" />
 </sequence>
</complexType>
<complexType name="computer-book">
 <complexContent>
  <extension base="book">
    <sequence>
     <element name="language" type="string"/>
    </sequence>
  </extension>
 </complexContent>
</complexType>

Here is an excerpt from an XML document:

<computer-book>
  <ident>12345</ident>
  <title>Decision Server Reference Manual</title>
   <language>Java IRL</language>
</computer-book>

Here is the XOM representation:

class Book extends IlrXmlObject
{
   …
     String ident;
     String title;
   …
}
class ComputerBook extends Book
{
  String language;
   …
}

And here is the rule:

rule processComputerBook
{
   when {
        ComputerBook ( language equals "Java" );
   }
   then {
      …
   }
}