2.1. Example of complete X-definition

Note that the X-definition in the example below has the attributes "name" and "root" (see line 1). The attribute "root" specifies which model (or models) from the X-definition can be used as the root elements of the input data. The attribute "name" contains the name of X-definition (it is required if the project is composed from more X-definitions). Note also that the element "xd:declaration" has the attribute scope="global", which specifies that the contents of the declaration are "visible" from all X-definitions (the attribute is optional and the default value is "local" - i.e. the declaration is visibble only from the this X-definition).

<xd:def xmlns:xd="http://www.xdef.org/xdef/4.2" name="Example" root="Inventory" >
  <xd:declaration scope="global">
    void message(String s) {
      outln(s);
    }
    int count = 0;
    type isbn int(10000000, 999999999);
  </xd:declaration>

  <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="isbn;"
          published="optional gYear();" >
      <Author xd:script="occurs *" >
        string()
      </Author>
      <Title>
        string();
      </Title>
    </Book>
  </Inventory>
 
</xd:def>
You can try it HERE