Schema representation of a "bitmask" type?

Andrey Brozhko

Usenet Archive
Joined
Dec 9, 2004
Messages
3
Reaction score
0
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
 

Andrey Brozhko

Usenet Archive
Joined
Dec 9, 2004
Messages
3
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top