1.3. Script of elements and text nodes

Let's now show how specify child nodes of an element and how to write the Script of elements. The Script of an element must be written in the special attribute “xd:script” (the prefix "xd" must correspond to the namespace of X-definition: "http://www.xdef.org/xdef/3.2").
In the example below we added the child elements "Title" and "Author". Both child elements contains a required text node. The value of the text node is described by the element "xd:script". We consider there are books with one author, more authors, or even without author. Therefore the quantifier of the element "Author" is specified as "occurs *" (i.e. none or more occurrences). Howewer, the child element "Title" must be one (i.e. it is required):

<Book isbn="required int(0, 9999999999);"
      published="optional gYear();" > 
  <Author xd:script="occurs *;" >
     <xd:text>
        required string(); /* name of author */"
     </xd:text>
  </Author>
  <Title xd:script="required;" >
     <xd:text>
        required string(); /* title of the book */"
     </xd:text>
   </Title>
</Book>

Since the default value of quantifier is "required" notice that the specification of such quantifier can be omitted:

<Book 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>

Prev  Content   Next