469,934 Members | 2,146 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

HELP - How to restrict elements in instance doc?

Hi,

Can anyone tell me if it is possible to create a XSD schema document
that will only allow certain elements to be displayed as available
within the instance document depending on say a parameter the user has
entered in the parent element?

For example:

In the instance document I have the following...

<file-layout xmlns="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test file:/D:/test.xsd"
name="myLayout"
locale="en_GB"
lastModifiedBy="Joe Bloggs"
type="BINARY">

'type' is a required attribute. Depending on if the user selects ASCII
or BINARY from the selection I want the instance document to then
display an appropriate child element.

For example, there may be a choice of either <ascii-parse> or
<binary-parse> as child elements. Both are distinctly different, and I
want the schema document (using the choice made by the user when
selecting 'type') to manage the validity of the instance document and
not have my code that reads in the instance document to have to check
to see if the user has made a mistake by say selecting type=ASCII and
then selecting <binary-parse> as the child element.

Any help would be appreciated.
Thanks.

Apr 5 '06 #1
1 1228
da*******@hotmail.com wrote:
Can anyone tell me if it is possible to create a XSD schema document
that will only allow certain elements to be displayed as available
within the instance document depending on say a parameter the user has
entered in the parent element?
It's possible for an instance document to explicitly say what type a
given element is to be treated as, using the xsi:type attribute.

If you want some other attribute to change the element's type as a
side-effect... I don't think that's supported. The type sets the legal
content, not vice versa.
For example, there may be a choice of either <ascii-parse> or
<binary-parse> as child elements. Both are distinctly different, and I
want the schema document (using the choice made by the user when
selecting 'type') to manage the validity of the instance document and
not have my code that reads in the instance document to have to check
to see if the user has made a mistake by say selecting type=ASCII and
then selecting <binary-parse> as the child element.


Personally, I'd fix that by not allowing this information to be
specified in a way that can conflict. Discard the type attribute and
just let the choice of element specify how its contents are to be processed.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Simon | last post: by
4 posts views Thread by Vijay Kumar R Zanvar | last post: by
7 posts views Thread by tweak | last post: by
33 posts views Thread by aaron | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.