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

Re: Is this premitted ?

  • From: Jeni Tennison <mail@j...>
  • To: Dimiter Naydenov <bluelight@o...>
  • Date: Mon, 02 Jul 2001 10:08:13 +0100

xml abstract complex type
Hi Dimiter,

> Is there a way to conditionally set the "required" or "prohibited"
> options for an attribute/child element, based on other element's
> presence/absence ?

As Eric's said, you can't do exactly this in XML Schema.  However, if
you're prepared to use the xsi:type attribute, then you can get close.
First define an abstract complex type for your tag element:

<xs:complexType name="tagType" abstract="true" />

Then define two complex types that derive from that type (here by
extension), one with the attribute and one with the element.

<xs:complexType name="tagWithAttr">
   <xs:complexContent mixed="true">
      <xs:extension base="tagType">
         <xs:attribute name="attr" type="xs:string" />
      </xs:extension>
   </xs:complexContent>
</xs:complexType>

<xs:complexType name="tagWithEle">
   <xs:complexContent mixed="true">
      <xs:extension base="tagType">
         <xs:sequence>
            <xs:element name="attr" type="xs:string" />
         </xs:sequence>
      </xs:extension>
   </xs:complexContent>
</xs:complexType>

[Note that you should change the definition of the attr element in the
above type to be a type other than xs:string if you want to allow it
to take complex values.]

Finally define the tag element to use the generic tagType complex
type:

<xs:element name="tag" type="tagType" />

When the tag element is present in the instance, it can't use the
tagType itself (since that type is abstract), so it has to use one of
the two types that are derived from it.  You can declare which one it
uses with the xsi:type attribute:

   <tag xsi:type="tagWithAttr" attr="val">text</tag>
   <tag xsi:type="tagWithEle">
      <attr>complex val</attr>
      text
   </tag>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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.