XS Annotation Examples


Some Commonly Used Annotation Attributes:
 
Annotation Attributes
Explanation
Outline
Can be applied to attribute, element or group. Take value true or false. If true, a relational table will be created for this attribute, element or group.
maptoclob
Can be applied to attribute or element.  Take value true or false. If true, the element or attribute will be mapped to a CLOB column.
edgemapping
Can be applied to element.  Take value true or false. If true, the subtree starting from the element will be mapped using  the edge mapping technique.
tablename Can be applied to attribute, element or global group.  The annotation value overwrites the table name generated by default.
fieldname
Can be applied to attribute or element.  The annotation value overwrites the field name generated by default.
Sqltype
Can be applied to attribute or element.  The value overwrites SQL type derived from schema data type.


 

The original XML schema has a top elment IMDB, which contains a list of SHOW elements.  The SHOW  Element has subelements TITLE and YEAR of integer type, a choice group which containts alternative elements BOXOFFICE and SEASONS, and a REVIEW element which may appear multiple times.
 
 <element name="IMDB" type="test:IMDBType"/>

  <complexType name="IMDBType"> 
    <sequence>
      <element name="SHOW" type="test:SHOWType" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
  </complexType>

  <complexType name="SHOWType">
    <sequence> 
      <element name="TITLE" type="integer"/>
      <element name="YEAR" type="integer"/>
      <choice>
        <element name="BOXOFFICE" type="integer"/>
        <element name="SEASONS" type="string"/>
      </choice>
      <element name="REVIEW" type="integer" minOccurs="0" maxOccurs="unbounded"/>
    </sequence> 
  </complexType> 

By default the following relation tables will be generated by ShreX:
 
CREATE TABLE IMDB
(
    id_ VARCHAR(128) NOT NULL,
    PRIMARY KEY (id_)
);

CREATE TABLE IMDB_SHOW
(
    id_ VARCHAR(128) NOT NULL,
    pid VARCHAR(128) NOT NULL,
    TITLE NUM(12) NOT NULL,
    YEAR NUM(12) NOT NULL,
    BOXOFFICE NUM(12),
    SEASONS VARCHAR(128),
    PRIMARY KEY (id_),
    FOREIGN KEY (pid) REFERENCES IMDB
);

CREATE TABLE IMDB_SHOW_REVIEW
(
    id_ VARCHAR(128) NOT NULL,
    pid VARCHAR(128) NOT NULL,
    REVIEW NUM(12),
    PRIMARY KEY (id_),
    FOREIGN KEY (pid) REFERENCES IMDB_SHOW
);

If we make the following annotations:
 <element name="IMDB" type="test:IMDBType"/>

  <complexType name="IMDBType"> 
    <sequence>
      <element name="SHOW" type="test:SHOWType" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
  </complexType>

  <complexType name="SHOWType">
    <sequence> 
      <element name="TITLE" type="integer" xs:outline="true" xs:tablename="Showtitle"/>
      <element name="YEAR" type="integer" xs:sqltype="NUMBER(4)"/>
      <choice>
        <element name="BOXOFFICE" type="integer"/>
        <element name="SEASONS" type="string"/>
      </choice>
      <element name="REVIEW" type="integer" minOccurs="0" maxOccurs="unbounded"/>
    </sequence> 
  </complexType> 

The generated relational schema is as the follow:
 
CREATE TABLE IMDB
(
    id_ VARCHAR(128) NOT NULL,
    PRIMARY KEY (id_)
);

CREATE TABLE IMDB_SHOW
(
    id_ VARCHAR(128) NOT NULL,
    pid VARCHAR(128) NOT NULL,
    YEAR NUM(4) NOT NULL,
    BOXOFFICE NUM(12),
    SEASONS VARCHAR(128),
    PRIMARY KEY (id_),
    FOREIGN KEY (pid) REFERENCES IMDB
);

CREATE TABLE Showtitle
(
    id_ VARCHAR(128) NOT NULL,
    pid VARCHAR(128) NOT NULL,
    TITLE NUM(12) NOT NULL,
    PRIMARY KEY (id_),
    FOREIGN KEY (pid) REFERENCES IMDB_SHOW
);

CREATE TABLE IMDB_SHOW_REVIEW
(
    id_ VARCHAR(128) NOT NULL,
    pid VARCHAR(128) NOT NULL,
    REVIEW NUM(12),
    PRIMARY KEY (id_),
    FOREIGN KEY (pid) REFERENCES IMDB_SHOW
);

If we make an annotation for edge mapping:
 
 <element name="IMDB" type="test:IMDBType"/>

  <complexType name="IMDBType" xs:edgemapping="true"
    <sequence>
      <element name="SHOW" type="test:SHOWType" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
  </complexType>

  <complexType name="SHOWType">
    <sequence> 
      <element name="TITLE" type="integer" />
      <element name="YEAR" type="integer" />
      <choice>
        <element name="BOXOFFICE" type="integer"/>
        <element name="SEASONS" type="string"/>
      </choice>
      <element name="REVIEW" type="integer" minOccurs="0" maxOccurs="unbounded"/>
    </sequence> 
  </complexType> 

The generated relational schema is as the follow:
 
CREATE TABLE IMDB
(
    source VARCHAR(128) NOT NULL,
    ordinal VARCHAR(128) NOT NULL,
    attrname VARCHAR(128) NOT NULL,
    isValue VARCHAR(128) NOT NULL,
    value VARCHAR(128) NOT NULL,
    PRIMARY KEY (source,ordinal)
);