Schema representation of a "bitmask" type?

A

Andrey Brozhko

Hi

I need to represent custom type system (ints, bytes, chars, enums,
bitmasks, arrays and some other types) in xml. It is easy to see how to
represent enums in xml (using xs:enumeration), the same is true for
numeric types. Even arrays have an obvious description in schema:

<complexType name="IntArray">
<sequence>
<element name="item" type="int" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>

But how about bitmasks? What's the most beautiful way to represent a
bitmask where values have names? It's just like enumeration but the
value at any time can be a disjunction of any number of valid names.
For example: if we have x = 0x01, y = 0x02 etc then the value may be
either x, or x|y, or y etc.. but it can not be specified with 0x01. I
don't think having "<myAttribute>x|y</myAttribute>" in the xml document
is a good idea. Any suggestions?

Cheers,
Kapitan
 
A

Andrey Brozhko

OK, here is what I come up with:

<xs:simpleType name="MyBitmapType">
<xs:choice>
<xs:element name="item" minOccurs="1" maxOccurs="unbounded">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="firstValue"/>
<xs:enumeration value="secondValue"/>
<xs:enumeration value="thirdValue"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:choice>
</xs:simpleType>


In this case something like:

<?xml version="1.0" encoding="UTF-8"?>
<test>
<item>firstValue</item>
<item>secondValue</item>
</test>

can be validated (which can be understood as "firstValue | secondValue").


Unfortunately, it validates the following thing as well:

<?xml version="1.0" encoding="UTF-8"?>
<test>
<item>firstValue</item>
<item>firstValue</item>
</test>

which is not exactly wrong (as you can do "firstValue | firstValue" and
the result will be OK), but it is not pretty... any suggestions?
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top