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

Re: dtd attributes

  • To: xml-dev@l...
  • Subject: Re: dtd attributes
  • From: "G. Ken Holman" <gkholman@C...>
  • Date: Mon, 26 Jul 2004 07:32:22 -0400
  • In-reply-to: <BAY17-F183qrB0Xn2Pi000829a2@h...>

dtd attributes
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@C...
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


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.