2.1. Example of complete X-definition

Note that the X-definition in the example below has attributes “name” and “root” (see line 1). The “root” attribute specifies which model represents the root element of input data. The “name” attribute is required as a reference name pointing to the X-definition in the collection of a set of X-definitions.

<xd:def xmlns:xd="http://www.xdef.org/xdef/4.2" name="Example" root="Inventory" >
    void message(String s) {
    int count = 0;

  <Inventory xd:script="init message('Created ' + now()); finally message('Processed ' + count + ' books');">
    <Book xd:script="occurs +; onAbsence error('No books!'); finally {count++; outln('isbn code: " ' + @isbn)};"
          isbn="int(10000000, 999999999);"
          published="optional gYear();" >
      <Author xd:script="occurs *" >
You can try it HERE