473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Schema representation of a "bitmask" type?

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

Jul 20 '05 #1
1 3198
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?

Andrey Brozhko wrote:
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

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
6
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
12
by: spibou | last post by:
Why is a pointer allowed to point to one position past the end of an array but not to one position before the beginning of an array ? Is there any reason why the former is more useful than the...
1
by: SoftwareTester | last post by:
I have following namespace Mine.Bits { public static class Bits {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.