[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Define a root in a DTD

  • From: Rick Jelliffe <ricko@a...>
  • To: xml-dev@l...
  • Date: Wed, 27 Jun 2001 16:42:52 +0800

dtd root
 From: "Peter Flynn" <peter@s...>

> At Tuesday, 26 June 2001, christine.coisy@m... 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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.