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

Re: XML Schema views - are they possible?


xml schema conditionally mandatory
While this approach "works", in practice wouldn't the documentation 
value of the schema (including documentation that can be generated from 
the schema) suffer?

Bob Foster

Michael Kay wrote:

> This is an excellent question and I'm not sure there's an easy answer. 
> It's a concrete coding question that's directly related to the rather 
> abstract debate we've been having over the last week about the need to 
> apply multiple schemas to the same document at different stages of 
> processing.
> Over on xsl-list the other day we had someone who wanted to 
> parameterize a schema, doing the equivalent of an #ifdef. I suggested 
> writing the schema in the form of an XSLT stylesheet, using 
> <xsl:param> and <xsl:if> to conditionally generate the operational 
> schema based on supplied parameters. So in the middle of an 
> xs:sequence, say, you could write
> <xs:element name="xyz" minOccurs="{if ($param='live') then 1 else 0}"/>
> (This example is XSLT 2.0/XPath 2.0 but you could equally do it using 1.0)
> Michael Kay
>
>     ------------------------------------------------------------------------
>     *From:* Cheng, Andy [mailto:Andy.Cheng@a...]
>     *Sent:* 27 August 2004 09:04
>     *To:* xml-dev@l...
>     *Subject:*  XML Schema views - are they possible?
>
>     Dear XML Dev List,
>
>     Hello, my name is Andy and I'm a newbie to this forum. I am
>     currently getting into the XML schema development and am having a
>     problem (hope you guys can help me out). I'm wondering is there a
>     possibility of having different XML Schema views (for reusability
>     purposes). Here is an example of code:
>
>     <xs:complexType name="StatusType">
>     <xs:all>
>     <xs:element name="StatusCode" minOccurs="0">
>     <xs:complexType>
>     <xs:simpleContent>
>     <xs:restriction base="tns:stringItemType">
>     <xs:minLength value="1"/>
>     <xs:maxLength value="10"/>
>     </xs:restriction>
>     </xs:simpleContent>
>     </xs:complexType>
>     </xs:element>
>     <xs:element name="StatusMessage" minOccurs="0">
>     <xs:complexType>
>     <xs:simpleContent>
>     <xs:restriction base="tns:stringItemType">
>     <xs:minLength value="1"/>
>     <xs:maxLength value="50"/>
>     </xs:restriction>
>     </xs:simpleContent>
>     </xs:complexType>
>     </xs:element>
>     </xs:all>
>     </xs:complexType>
>
>     These two elements are optional. However, I want to reuse the
>     complexType and change the 'StatusCode' element to mandatory ie
>     change the value of 'minOccurs' to 1. What I have found so far is
>     that I could use a 'restriction' element to change the value,
>     hence the code:
>
>     <xs:element name="Status">
>     <xs:complexType>
>     <xs:complexContent>
>     <xs:restriction base="tns:StatusType">
>     <xs:all>
>     <xs:element name="StatusCode">
>     <xs:complexType>
>     <xs:simpleContent>
>     <xs:restriction base="tns:stringItemType">
>
>     <xs:minLength value="1"/>
>
>     <xs:maxLength value="10"/>
>
>     </xs:restriction>
>     </xs:simpleContent>
>     </xs:complexType>
>     </xs:element>
>     <xs:element name="StatusMessage" minOccurs="0">
>     <xs:complexType>
>     <xs:simpleContent>
>     <xs:restriction base="tns:stringItemType">
>
>     <xs:minLength value="1"/>
>
>     <xs:maxLength value="50"/>
>
>     </xs:restriction>
>     </xs:simpleContent>
>     </xs:complexType>
>     </xs:element>
>     </xs:all>
>     </xs:restriction>
>     </xs:complexContent>
>     </xs:complexType>
>     </xs:element>
>
>     What I would like to achieve is:
>     1. if I wanted to change the restriction values in the
>     complexType, the change would ripple through to all elements using
>     this complexType. However, this is not the case. When placing a
>     'restriction' element, in XMLSpy it duplicates all the elements
>     from the complexType
>
>     2. If I didn’t want this element to be passed at all ie make
>     maxOccurs ='0' (PS is this bad coding?), I don’t want the XML
>     Schema to validate the element. After a few examples by putting
>     the element in, the XML schema still does validate the element,
>     although its not wanted.
>
>     Does anyone know how to get around this?? Or perhaps is there an
>     alternative solution?
>
>     Thanks a lot!
>
>     Regards,
>
>     Andy Cheng
>     *Australian Taxation Office *
>     *INFORMATION COMMUNICATIONS & TECHNOLOGY*
>     Software Development Quality & Productivity
>
>     /andy.cheng@a.../
>



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.