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

Re: How to avoid the sequens of child elements in DTD, yet kee


elements in dtd
Albena,

You can't as far as I know implement this in DTDs. However it is fairly
simple to implement in Schematron, with a grand total of four
assertions.

For more details of schematron see
http://www.ascc.net/xml/resource/schematron/schematron.html

Francis.

<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
  <sch:title>movies</sch:title>
  <sch:pattern name="Header">
    <sch:rule context="Header">
      <sch:assert test="Identification"
        >The Header must have one or more Identification
elements.</sch:assert>
      <sch:assert test="Category"
        >The Header must have one or more Category
elements.</sch:assert>
    </sch:rule>
    <sch:rule context="Header/*">
      <sch:assert test="self::Identification or self::Category or
self::Weight or self::Keyword"
        >Children of Header must be Identification, Category, Weight or
Keyword, but this was a <name/>.</sch:assert>
      <sch:assert test="not(preceding::*[1][name() !=
name(current())][preceding::*[name() =  name(current())]])"
        >This <name/> was not grouped with the other
<name/>s.</sch:assert>
    </sch:rule>
  </sch:pattern>
</sch:schema>

---
C:\xml\schematron>sch-basic t-good.xml t
movies

C:\xml\schematron>sch-basic t-bad.xml t
movies
In pattern not(preceding::*[1][name() !=
name(current())][preceding::*[name() = name(current())]]):
   This Keyword was not grouped with the other Keyword s.
---

Hope this helps -

Francis.


Albena Georgieva wrote:
> 
> Hi there,
> 
> I am creating a DTD document and I have difficulty to express
> that the element type Header:
> 
> 1. must have one and only one child element of type Indentification
> 2. Can have [0 ... 1] Weight children elements
> 3. Must have at least one Category child element
> 4. Can have [0 ... n] Keywords
> 5. The order of the different children is not important
> 6. If there are several children of the same type, then they should be
> following each other
> 
> Good example:
> <Header>
>    <Keyword>Navratilova</Keyword>
>    <Keyword>Tennis</Keyword>
>    <Identification id="1111"/>
>    <Category>Sports</Category>
> </Header>
> Another good example:
> <Header>
>    <Category>Sports</Category>
>    <Keyword>Navratilova</Keyword>
>    <Keyword>Tennis</Keyword>
>    <Identification id="1111"/>
>    <Weight priority="3"/>
> 
> </Header>
> 
> Not accepted example
> <Header>
>    <Category>Sports</Category>
>    <Keyword>Navratilova</Keyword>
>    <Identification id="1111"/>
>    <Keyword>Tennis</Keyword>
>    <Weight priority="3"/>
> </Header>
> 
> I tried as follows:
> 
> <!ELEMENT header (Identification| Weight? | Category+ | Keyword* )+>
> But then also this example becomes valid which is not what I am aiming to:
> 
> <Header>
>    <Category>Sports</Category>
>    <Keyword>Navratilova</Keyword>
>    <Keyword>Tennis</Keyword>
>    <Identification id="1111"/>
>    <Weight priority="3"/>
>    <Category>Sports</Category>
>    <Identification id="2222"/>
> 
> </Header>
> 
> And if I say so:
> <!ELEMENT header (Identification, Weight?, Category+, Keyword* )>
> 
> It is better, but then we have to comply to the sequence of the children,
> which is what I want to avoid ...
> Any ideas, help please?
> 
> I wish you all a very nice day!
> Greeting,
> Albena Georgieva
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>

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.