CIS97 YT > Relax NG Projects > Family Tree Markup Grammar

Relax NG Projects
Family Tree Markup Language

Project Index | Documentation | Relax NG | Sample XML File


<grammar 
    xmlns="http://relaxng.org/ns/structure/1.0"
    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

<start>
    <element name = "family_tree">
        <ref name = "peopleRef"/>
        <ref name = "familiesRef"/>
    </element>
</start>

<define name = "peopleRef">
    <element name = "people">
        <oneOrMore>
            <ref name = "personRef"/>
        </oneOrMore>
    </element>
</define>

<define name = "personRef">
    <element name = "person">
        <attribute name = "id">
            <data type="ID"/>
        </attribute>
        <attribute name = "gender">
            <choice>
                <value type = "string">m</value>
                <value type = "string">f</value>
            </choice>
        </attribute>
        <element name = "name">
            <group>
                <element name = "given"><text/></element>
                <element name = "surname"><text/></element>
            </group>
        </element>  
        <interleave>
            <optional>
                <element name = "birth">
                    <ref name="place-date"/>
                </element>
            </optional>
            <optional>
                <element name = "death">
                    <ref name="place-date"/>    
                </element>
            </optional>
            <optional>
                <element name = "spouse">
                    <ref name = "person-idref">
                 </element>
            </optional>
            <optional>
                <element name = "father">
                    <ref name = "person-idref"/>
                </element>
            </optional>
            <optional>
                <element name = "mother">
                    <ref name = "person-idref"/>
                </element>
            </optional>
        </interleave>
    </element>
</define>

<define name = "familiesRef">
    <element name = "families">
        <oneOrMore>
            <element name = "family">
                <attribute name = "id">
                    <data type="ID">
                        <param name ="pattern">[f]\d{1,}</param>
                    </data>
                </attribute>
                <interleave>
                    <optional>
                        <element name = "husband">
                            <ref name="person-idref"/>
                        </element>
                    </optional>
                    <optional>
                        <element name = "wife">
                            <ref name="person-idref"/>
                        </element>
                    </optional>
                    <optional>
                        <zeroOrMore>
                            <element name = "child">
                                <ref name="person-idref"/>
                            </element>
                        </zeroOrMore>
                    </optional>
                    <optional>
                        <element name = "marriage">
                            <interleave>
                                <optional>
                                    <element name = "date">
                                        <data type="string">
                                            <param name = "pattern">\d{4}-\d{2}-\d{2}</param>
                                        </data>
                                    </element>
                                </optional>
                                <optional>
                                    <element name = "place"><text/></element>            
                                </optional>
                            </interleave>          
                        </element>
                    </optional>
                    <optional>
                        <element name = "description"><text/></element>
                    </optional>
                </interleave>
            </element>
        </oneOrMore>
    </element>
</define>

<define name="place-date">
    <interleave>
        <element name = "place">
            <data type="string">
                <param name ="pattern">\w+</param>
            </data>
        </element>
        <element name = "date"> 
            <data type="string">
                <param name = "pattern">\d{4}-\d{2}-\d{2}</param>
            </data>
        </element>     
    </interleave>
</define>

<define name="person-idref">
    <attribute name = "idref">
        <data type = "IDREF">
            <param name="pattern">[p]\d{1,}</param>
        </data>
    </attribute>
</define>
</grammar>