XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Brent NelsonSubject: Applying constraints & naming when Elements reference other Elements
Author: Brent Nelson
Date: 18 Jun 2008 12:28 AM
I'm hoping forum participants can help me figure something out. I'm developing an XML Schema, and need to re-use Elements that have been previously defined. I'm doing this by referencing the defined Elements where they are used in a Complex Type, and not re-declaring the Elements at the global level. This all works great, producing valid xml schema.

My problem comes as I try to take this approach to the next step by applying constraints and local naming:

1) I need to apply constraint facets such as maxLength & minLength to Elements that reference other Elements. I'm familiar with applying facets to Elements, which is done in their global declaration. But where an Element references another Element, and thus is not declared at a global level, how does one apply a constraint to it? If so, what is the syntax for it?

2) I also need to re-name Elements. E.g., I want to create an Element named "MyElement" which references "other:TheirElement". Is there a way to reference another Element but not inherit the name it has in the namespace where it is declared? If so, what is the syntax for such a reference?

Any help would be much appreciated.

Brent Nelson

Postnext
Alberto MassariSubject: Applying constraints & naming when Elements reference other Elements
Author: Alberto Massari
Date: 18 Jun 2008 03:41 PM
Hi Brent,
you can specify the number of repetitions of the same referenced element by using a syntax like

<xsd:element ref="globalElement" minOccurs="5" maxOccurs="10"/>

If you want to rename an element, you should instead move the definition of the global element to a global type, change the global element to have a type="globalType" attribute, and then define the "myElement" local element using the same global type.

Hope this helps,
Alberto

Postnext
Brent NelsonSubject: Applying constraints & naming when Elements reference other Elements
Author: Brent Nelson
Date: 18 Jun 2008 06:36 PM
Thanks for the quick reply!

Just to make sure I understand correctly, let me see if I can rephrase. Since I want "MyElement" to be exactly like "other:TheirElement" in every way but name, I need to create "MyElement" using the type used to create "other:TheirElement". So say I look up "TheirElement" in the "other" namespace, find that its type is "other:TheirType". Then I need to create "MyElement" by pointing its type attribute at "other:TheirType". Correct?

If I understand correctly, then you've also answered my question about applying constraint facets. If I create "MyElement" as above, then I'll be declaring it at the global level. Therefore, I can apply "maxLength", etc. constraints to it in the familiar way.

Is it true that constraints can only be applied in this way? I.e., if I need to apply constraint facets to an element, that element can't reference another element but must reference a type, instead. Correct?

Thanks again,
Brent Nelson

Postnext
Alberto MassariSubject: Applying constraints & naming when Elements reference other Elements
Author: Alberto Massari
Date: 19 Jun 2008 05:53 AM
Hi Brent,
you are correct; when you reference an element definition, what you can do is just specify how many times that element can be present; if you need to manipulate some of its properties (name, length, allowed values, etc..) you need to access the complex/simple type of that element and either reuse it entirely (if you just need to change the name) or restrict/extend it inside the element definition (to change the min/max length, remove or add enumeration values).

Alberto

Posttop
Brent NelsonSubject: Applying constraints & naming when Elements reference other Elements
Author: Brent Nelson
Date: 19 Jun 2008 01:37 PM
Thanks, Alberto. This helps a lot!
Brent

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.