[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|