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

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Define a root in a DTD



 From: "Peter Flynn" <peter@silmaril.ie>

> At Tuesday, 26 June 2001, christine.coisy@modicon.com wrote:

> >    I have few elements in a DTD and I want to explicity declare
> >   one as the root to be used in XML, not the others, is there a
>>   way for that ?

No, not explicitly.

The Schematron schema language was designed to augment
other schema languages.  Every schema language has some
deficiencies: there are lots of trade-offed decisions that that are
really coin-tosses.  http://www.ascc.net/xml/schematron/1.5

To declare an element must be a root:
 <schema xmlns="http://www.ascc.net/xml/schematron">
     <pattern>
        <rule context="/">
            <assert test="/x or /y or /z"
            >The top-level element must be x or y or z.</assert>
        </rule>
     </pattern>
</schema>

> You don't need to. The root element is always the one that
> does not appear in the content model of any other element
> type. All other elements must get mentioned somewhere else,
> but the root element never does. eg
>
> <!ELEMENT name (#PCDATA)>
> <!ELEMENT phone (#PCDATA)>
> <!ELEMENT email (#PCDATA)>
> <!ELEMENT person (name,phone,email)>
> <!ELEMENT directory (person+)>
>
> "directory" will be deduced as the root element because it
> does not appear in the content model of any other element
> type.

The equivalent in Schematron for this is (untested):

 <schema xmlns="http://www.ascc.net/xml/schematron">
     <pattern>
        <!-- Fix top-level element -->
        <rule context="/">
            <assert test="/directory"
            >The top-level element must be "directory".
        Directories contain "person" elements.</assert></rule>

        <!-- Content models rules -->
        <rule context="directory">
            <assert test="person"
            >The "directory" element should contain one or more "person"
elements. Person element have elements for "name", "phone", and
"email".</assert></rule>
        <rule context="person">
            <assert test="*[1][self:name]"
            >The first element in a "person" should be "name" element.
        The element contains a text string, with the full name
        of the person.</assert>
            <assert test="*[2][self:phone]"
            >The second element in a "person" should be "phone" element.
The phone number should use digits, not alphabetic characters. (If you do
not wish to receive obscene phone calls
in the middle of the night, please enter the phone number of
some other person.)</assert>
            <assert test="*[3][self:email]"
            >The third element in a "person" should be "email",
           giving the email address of the person.
           This address will only be used for spamming purposes.
           The email address should contain a "@" character.</assert>
            <report test="*[4][self:name]"
            >The person element should only contain three elements (name,
phone and email).</report>
        </rule>
        <rule context="name|phone|email">
            <assert test="count(*)=0"
            >The <name/> element should have no child elements</assert>
        </rule>

        <!-- Make the content models closed -->
        <rule context="*">
            <report test="1=1"
            >The <name/> element is not known.</report>
        </rule>
     </pattern>
</schema>

Cheers
Rick Jelliffe