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/3.2" name="Example" root="Inventory" >
  <xd:declaration>
    void message(String s) {
      outln(s);
    }
    int count = 0;
  </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="int(0, 9999999999);"
          published="optional gYear();" >
      <Author xd:script="occurs *" >
        <xd:text> string() </xd:text>
      </Author>
      <Title>
        <xd:text> string() </xd:text>
      </Title>
    </Book>
  </Inventory>
 
</xd:def>
You can try it HERE
Prev  Content   Next