Can XML Schema represent this?

S

Steven Burr

I would like to restrict the values of an attribute to boolean
expressions combining enumerated values. Is this possible?

An example instance document might look something like:

<myElement expression="apples OR oranges"/>

I thought I'd start with something like:

<xs:element name="myElement" type="myElementType"/>

<xs:complexType name="myElementType">
<xs:attribute name="expression" type="myAttributeType"/>
</xs:complexType>

<xs:simpleType name="myAttributeValues">
<xs:restriction base="xs:string">
<xs:enumeration value="apples"/>
<xs:enumeration value="oranges"/>
<xs:enumeration value="bananas"/>
<xs:enumeration value="pears"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="myAttributeType">
<xs:restriction base="myAttributeValues">

<!-- WHAT GOES HERE TO ALLOW BOOLEAN EXPRESSIONS
OF THE ENUMERATED TYPE VALUES? -->

</xs:restriction>
</xs:simpleType>
 
R

Richard Tobin

Steven Burr said:
I would like to restrict the values of an attribute to boolean
expressions combining enumerated values. Is this possible?

You would have to use a regular expression. Something like

"(apples|oranges|bananas|pears) (OR|AND) (apples|oranges|bananas|pears)"
<xs:restriction base="myAttributeValues">

<!-- WHAT GOES HERE TO ALLOW BOOLEAN EXPRESSIONS
OF THE ENUMERATED TYPE VALUES? -->

</xs:restriction>

This is not going to work, since it's not a restriction of the base
type. If a type R is a restriction of a type B, then all legal R values
are legal B values. But "apples OR oranges" is not a legal value for
myAttributeValues.

-- Richard
 
S

Steven Burr

Richard said:
You would have to use a regular expression. Something like

"(apples|oranges|bananas|pears) (OR|AND) (apples|oranges|bananas|pears)"

I was trying to avoid this, as it gets more an more unwieldy the more
items there are in the enumeration.
This is not going to work, since it's not a restriction of the base
type. If a type R is a restriction of a type B, then all legal R values
are legal B values. But "apples OR oranges" is not a legal value for
myAttributeValues.

Would an extension work then? That would define a superset rather than a
subset. I take it there is no way to indicate a token from some
enumeration in a regular expression pattern? Is there any other facet
that I could extend to achieve this? If not, I'll either have to use the
regular expression workaround or else just leave it type="xs:string" and
call it a day.

Thanks,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top