OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

relax-ng message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Subject: Convention for mimicking inheritance in RELAX NG


In my talk at Extreme, I argued that inheritance can be mimicked in 
RELAX NG by using a simple convention.

I used the attached example in my talk.  I am going to send this to GCA 
soon.


1) Schema mimicking a class hierarchy

<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/0.9"
  xmlns:a="http://relaxng.org/ns/annotation/0.9"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"
  ns="http://www.xml.gr.jp/xmlns/ex">

  <start>  
    <element name="schemaLanguage">
      <optional>
        <element name="mascot">
          <ref name="referenceToAnimal"/>
        </element>
      </optional>
      <element name="specifications">
        <list>
          <zeroOrMore>
            <data type="string"/>
          </zeroOrMore>
        </list>
      </element>
    </element>
  </start>

  <div>
    <a:documentation>Abstract superclass: animal</a:documentation>

    <define name="referenceToAnimal"><notAllowed/></define>
    <define name="animal"><empty/></define>
  </div>

  <div>
    <a:documentation>Abstract superclass: mamal</a:documentation>

    <define name="referenceToAnimal" combine="choice">
      <ref name="referenceToMamal"/>
    </define>
    <define name="referenceToMamal"><notAllowed/></define>
    <define name="mamal"><ref name="animal"/><empty/></define>
  </div>

  <div>
    <a:documentation>Concrete class: cat</a:documentation>

    <define name="referenceToMamal" combine="choice">
      <ref name="referenceToCat"/>
    </define>

    <define name="referenceToCat">
      <attribute name="type">
        <value>cat</value>
      </attribute>
      <ref name="cat"/>
    </define>

    <define name="cat">
      <ref name="mamal"/>
      <optional>
        <attribute name="color"/>
      </optional>
    </define>
  </div>

  <div>
    <a:documentation>Concrete class: fortuneCat</a:documentation>

    <define name="referenceToCat" combine="choice">
      <ref name="referenceToFortuneCat"/>
    </define>

    <define name="referenceToFortuneCat">
      <attribute name="type">
        <value>fortuneCat</value>
      </attribute>
      <ref name="fortuneCat"/>
    </define>

    <define name="fortuneCat">
      <ref name="cat"/>
      <attribute name="raisedPaw">
        <a:documentation>
           right: inviting money
        </a:documentation>
        <a:documentation>
           left:  inviting people
        </a:documentation>
        <choice>
          <value>right</value>
          <value>left</value>
        </choice>
      </attribute>
    </define>
  </div>

</grammar>
  

2) a valid instance

<schemaLanguage xmlns="http://www.xml.gr.jp/xmlns/ex"> 
  <mascot type="cat" color="white"/>
  <specifications/>
</schemaLanguage>

3) another valid instance

<schemaLanguage xmlns="http://www.xml.gr.jp/xmlns/ex"> 
  <mascot type="fortuneCat" raisedPaw="left" color="white"/>
  <specifications/>
</schemaLanguage>


Cheers,

Makoto


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Powered by eList eXpress LLC