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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: dtd attributes

[ Lists Home | Date Index | Thread Index ]

At 2004-07-26 10:46 +0100, james walker wrote:
>Does anybody know how to force an attribute to be used when another 
>attribute is used?

This is called a co-occurrence constraint.

>I have a set of tags below:
><portlet imageurl="http://....."; alt="this is an image" >
></portlet>
>sometimes the portlet may have an image and sometimes it may not. How do i 
>construct the dtd attributes to force the person writing the xml to always 
>have an alt attribute for every imageurl attribute.

DTD syntax is not expressive enough to express such a co-occurrence 
constraint.  Neither is W3C Schema.

You can express this in RELAX-NG.  An example is below.  Note how the 
parentheses makes the pair of attributes an item that, as a pair, is 
optional.  This means that neither may be allowed, or both may be allowed, 
but not only just one.

I hope this helps.

T:\ftemp>type walker.rng
start = element portlet
   {
    (
      attribute imageurl { text },
      attribute alt { text }
    )?
   }

T:\ftemp>type walker1.xml
<portlet imageurl="http://....."; alt="this is an image" >
</portlet>
T:\ftemp>jing -c walker.rng walker1.xml

T:\ftemp>type walker2.xml
<portlet>
</portlet>
T:\ftemp>jing -c walker.rng walker2.xml

T:\ftemp>type walker3.xml
<portlet imageurl="http://.....";>
</portlet>
T:\ftemp>jing -c walker.rng walker3.xml
T:\ftemp\walker3.xml:1: error: required attributes missing

T:\ftemp>

--
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS